//connect to the server
//$link = mysql_connect('localhost','','');
$link = mysql_connect('localhost','frlht','ucy59er');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
//select the database
mysql_select_db('frlhtu') or die('Can not select database');
//generate next (unique) id.
function get_next_id($field)
{
$sql="select $field from id_mast";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$sql="update id_mast set $field=$field+1";
$result=mysql_query($sql);
return $row[$field]+1;
}
function generate_valid_id($id,$maxlen)
{
$lendif=$maxlen-strlen($id);
for($i=0;$i<$lendif;$i++) $id='0'.$id;
return $id;
}
function get_list_data($table,$id,$fieldary,$where='',$sql='')
{
if(!$sql) $sql="select * from $table";
if($where) $sql.=" $where";
$result=mysql_query($sql);
$ary = Array();
while($row=mysql_fetch_array($result))
{
$dval='';
foreach($fieldary as $val) {
if($val=='Current_desg') $dval.="(".$row["$val"].") ";
else $dval.=$row["$val"]." ";
}//foreach
$ary[$row["$id"]]=trim($dval);
}//while
return $ary;
}
function fetch_me($table1,$fld1,$fldname,$fldvalue,$table2='',$joincondn='')
{
if($table2=="")
{ $fquery="select $fld1 from $table1 where $fldname='$fldvalue'";
}
else
{
$fquery="select $fld1 from $table1 inner join $table2 on $joincondn where $fldname='$fldvalue'";
}
$fresult=mysql_query($fquery) or die(mysql_error());
$frs=mysql_fetch_array($fresult);
return $frs[0];
}
// FUNCTION TO GET SUBJECTS ASSIGNED TO WEBSITE.
function get_subjects()
{
$host = "www.homeremedy.in";
//$host = "envis.frlht.org.in";
//$e = explode(".",$_SERVER['HTTP_HOST']);
$e = explode(".",$host);
if($e[0]=="www")
{ //print "
URL starts with 'www' and site is : $e[1]
";
$tmp = $e[1];
}
else
{ //print "
Sub-domain found : $e[0]";
$tmp = $e[0];
}
$siteid = fetch_me("websites","site_id","second_name",$tmp);
$q = mysql_query("SELECT * FROM subject_site WHERE site_id = $siteid");
while($r = mysql_fetch_object($q))
{ $subname = fetch_me("subject","sub_name","sub_id",$r->subject_id);
if($sub_arr=="")
$sub_arr = "\"".$r->subject_id."\""."=>\"".$subname."\"";
else
$sub_arr .= ",". "\"".$r->subject_id."\""."=>\"".$subname."\"";
}
//print "Array of subjects is: ".$sub_arr;
//$pre = "Array ("; $pos = ")";
//$sub_arr = $pre.$sub_arr.$pos;
return $sub_arr;
}
function format_date_db($date)
{ $dtary = explode("-",$date);
//print_r($dtary);
if (count($dtary)>1)
{
return $dtary[2]."-".$dtary[1]."-".$dtary[0];
}
else
{
return($date);
}
}
function format_date_db1($date)
{ $dtary = explode("-",$date);
if (count($dtary)>0)
{
return $dtary[2]."-".$dtary[1]."-".$dtary[0];
}
else
{
return($date);
}
}
?>