I have a php function that I'm hoping will return all data. The problem right now is it will return the first row called then hang out and I'm not sure why.
function get_user_info($id,$field='')
{
//connect to database
include_once("../config.php");
$qry= "SELECT `$field` FROM `".$user_table."` WHERE `id` ='$id'";
//die($qry);
$result=mysql_query($qry);
if($result) {
if(mysql_num_rows($result)>0) {
//query successful
$data=mysql_fetch_row($result);
$user_info= $data[0];
}
else{
$user_info ="invalid field";
}
}
else{
$user_info="invalid data";
}
return $user_info;
}
If I run a function like echo (get_user_info($user_id,'username')." ".get_user_info($user_id,'username')); It returns username invalid data For the life of me I can't figure out why it won't get the data assocated with each row of get_user_data
EDIT: It seems to be dying at $result=mysql_query($qry); which returns Incorrect table name ''
EDIT2: Looks like the problem was that I was only including the config file once and using a variable for my table name which was getting unset when I tried to call it a second time.
EDIT 3: Here is the final function
//connect to database
if(file_exists('..config.php')){
include_once("../config.php");
}
function get_user_info($id,$field)
{
//get users table
global $user_table_name;
$qry= "SELECT `$field` FROM `$user_table` WHERE `id` ='$id'";
$result=mysql_query($qry) or die(mysql_error());
if($result) {
if(mysql_num_rows($result)>0) {
//query successful
$data=mysql_fetch_row($result);
$user_info= $data[0];
}
else{
$user_info =$qry;
}
}
else{
$user_info="invalid data";
}
return $user_info;
}