Page is a not externally linkable
LinusIT - 11:59 am on Nov 21, 2012 (gmt 0)
Hi
I'm trying to create a function that returns an array of data from a MySQL database but am having some trouble, I.E it isn't working.
I can get the array to work outside of the function but once I put the code into a function, it stops working.
Working array:
$sqlx = "SELECT vehicle_id FROM vehicles WHERE vehicle_diary=1";
$resultx = mysql_query($sqlx);
while ($rowx = mysql_fetch_row($resultx))
{
$result_array[] = $rowx[0];
}
print_r($result_array);
This returns - Array ( [0] => 1 [1] => 3 )
Not working function:
function diary_vehicle_select() {
$sqlx = "SELECT vehicle_id FROM vehicles WHERE vehicle_diary=1";
$resultx = mysql_query($sqlx);
$result_array = array();
while ($rowx = mysql_fetch_row($resultx))
{
$result_array[] = $rowx[0];
}
return $result_array;
}
This returns - Array
I have no doubt this is obvious to someone pretty much straight away. I just can't solve it myself. Thanks