I have a silly problem. I can't figure it out, maybe someone can help me.
This function is designed to make it easy for me to grab data out of my database. I just input what I want and let php do everything for me. My problem is when the sql did not find anything and returns a NULL value. When the program gets to:
if (!isset($data[1]))
$data = $data[0];
it calls up a "Notice: Undefined variable". I need this to go away and have tried all sorts of isset(), is_array(), ... with no luck. Can someone help me fix this?
Here's my function and function call:
$check = database_grab("data","table","this = '$that' AND what = '$why'","last_updated");
function database_grab($select,$table,$where,$order)
{
$query = "SELECT $select FROM $table WHERE $where ORDER BY $order;";
$result = mysql_query($query);
$i=0;
if (substr($select,0,9)=="DISTINCT ")
$select = substr($select,9);
$token = strtok($select,",");
while($token !== false)
{
$field[] = $token;
$token = strtok(",");
}
while($i<mysql_num_rows($result))
{
foreach($field as $val)
$data[] = mysql_result($result,$i,$val);
$i++;
}
if (!isset($data[1]))
$data = $data[0];
return $data;
} // function database_langGrab()
I'd appreciate any help you can give. Thanx!