I have a MySQL query that returns a list of results:
Code: Select all
SELECT
id AS 'ID',
date AS 'Date'
from table tab1;
So I figure I need to put the result into an Array, and then I can just call off the relevant part to display, but I am getting duplicates of everything.
I have:
Code: Select all
$a = 0;
$dataArray = array();
if (isset($runid)) {
mysql_select_db($db, $connection) ;
$result = mysql_query ($query, $connection);
while ($row = mysql_fetch_assoc($result))
foreach ($row AS $attribute )
{
$dataArray[$a]['id'] = $row['id'] ;
$dataArray[$a]['date'] = $row['Date'];
$a = $a++;
}
} else {
print "<p>No Data Found</p>"; };
Array (
[0] => Array ( [id] => 123456 [date] => 2010-09-07 06:30:02 )
[1] => Array ( [id] => 789012 [date] => 2010-09-06 05:45:08 )
[2] => Array ( [id] => 345678 [date] => 2010-09-08 03:20:21 )
Instead I am getting
Array (
[0] => Array ( [id] => 381357 [date] => 2010-09-07 06:30:02 )
[1] => Array ( [id] => 381357 [date] => 2010-09-07 06:30:02 )
[2] => Array ( [id] => 381358 [date] => 2010-09-08 03:20:21 )
[3] => Array ( [id] => 381358 [date] => 2010-09-08 03:20:21 )
As you can see, the data is duplicated, so that [0] and [1] are the same, as are [2] and [3] etc.
Am I missing something really obvious here?