Hi,
I have made a function to make it more convenient for me to run SQL queries and produce an associative array from the result. However, I am having some problems with the function.
Here's the function code:
function getarray($q){
if(!$result = mysql_query($q)){
echo mysql_error();
}
else{
$item = array();
$item = mysql_fetch_assoc($result);
return $item;
}
}
and I am calling it like this:
$row = getarray("SELECT * FROM events");
for($i = 0;$i<=sizeof($row);$i++){
$eventtime = date("D, jS M y",$row['eventtime']);
echo '<tr><td>'.$eventtime.'</td></tr>';
echo '<tr><td>'.$row['event'].'</td></tr>';
}
The database contains 4 rows but the code above is returning 9 lines in the HTML and the values of each 1 hold the values of the 4th row in the database.
Any ideas?
Thanks.