I’m not sure I understand how arrays work in MySQL.
I had a table that has 1 column called “id”, each row has a random numeric value for “id”. (the rows are in order by the date they were put into the table (another column called TimeStamp)
So I may have:
//row#: id#
row1: 5
row2: 17
row3: 2
row4: -54
row5: 18
Now I can re-arrange them by “ORDER BY” and put them in ascending order by “id”
$table1 = mysql_query("SELECT * FROM table1 ORDER BY id ASC") or die(mysql_error());
$orderedArray = mysql_fetch_array($table1);
So now I have an array ($orderedArray).. It should be like this right?:
row4: -54
row3: 2
row1: 5
row2: 17
row5: 18
The “id” column is now in order instead of the number after row (in my case you would see a postdate(timestamp) instead of row1, or row3, but I just used a “row#” naming system to make the example easier…
So I have this array… now let’s say I wanted to print the third row of my ORDER BY themed array, (aka the row in my original table with the third highest value in the “id” column… What would my code be?
I assumed something like this (but it didn’t work):
$row3id = $orderedArray['id', 3];
print $row3id;
Anyone know? Thanks!
Try:
PHP arrays start with 0 as the first index.
Also,
mysql_fetch_arrayhas an optional parameterresult_typewhich lets you decide how you want your results returned. The default isMYSQL_BOTH, which is what is used in your case seeing you didn’t identify theresult_typeso you have an array result with associative and numbered indexes.See here for more info:
http://php.net/manual/en/function.mysql-fetch-array.php