My code is:
$query = "SELECT a.hash, a.full, a.partial, a.servers, a.lastupd, b.full, b.partial, b.servers, b.lastupd FROM table1 AS a, table2 AS b WHERE a.hash='".$hashcode."' AND a.hash=b.hash;";
$result = mysql_query($query);
then I perform a
print_r(mysql_fetch_array($result));
And I get this weird output:
Array
(
[0] => blah
[hash] => blah
[1] => 1,1,1
[full] => 0,1
[2] => 1,2,1
[partial] => 4,2
[3] => srv1,srv2,srv3
[servers] => srv2,srv3
[4] => 0000-00-00 00:00:00
[lastupd] => 0000-00-00 00:00:00
[5] => 0,1
[6] => 4,2
[7] => srv2,srv3
[8] => 0000-00-00 00:00:00
)
Why there’s data repetition for b table and doesn’t create an associative array with keys a.* and b.*?
Note: the timestamps set to 0 are correct
Because mysql_fetch_array returns both associative and numeric array. Use mysql_fetch_assoc, if you only need associative array.
(By the way, mysql is deprecated, read about using mysqli or PDO)