I am facing a problem while wanting to fetch all the rows from my following table namely date.
id name username app sdate edate
=== ======= ======== === ===== ======
1 tanvir tanvir 1 2012 2012
2 Ranvir Ranvir 1 2011 2013
3 john john 2 2011 2012
4 Rakib Rakib 1 2011 2012
I use the following MySQL Query:
$date = mysql_query("select * from `date`");
$date_row = mysql_fetch_array($date);
But it is only returning a single row.
How can I put all of the rows into a two dimensional array?
Well of course it's only returning one row, that's what mysql_fetch_array does:
mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both
Now, to build an array of your rows, you just have to iterate over them:
$all_rows = array();
while($row = mysql_fetch_assoc($date)) $all_rows[] = $row;
Notice how I use mysql_fetch_assoc here. You should NEVER use mysql_fetch_array unless you very specifically need both numeric and associative indices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With