Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help ordering data from mysql_fetch_array()

I'm having a hard time organizing the data that I get from mysql_fetch_array().

I have a DB table with that looks something like this:

+---------------------+------------------+---------------+--------+---------+
| date                | name             | indexed_pages | nameID | entryID |
+---------------------+------------------+---------------+--------+---------+
| 2012-06-15 21:18:06 | site1.com        |           200 |      1 |       1 |
| 2012-06-15 21:18:10 | site2.com        |            25 |      2 |       1 |
| 2012-06-15 21:18:13 | site3.com        |            12 |      3 |       1 |
| 2012-06-15 21:18:16 | site4.com        |             8 |      4 |       1 |
| 2012-06-15 21:18:19 | site5.com        |             2 |      5 |       1 |
| 2012-06-16 00:11:12 | site1.com        |           191 |      1 |       2 |
| 2012-06-16 00:11:21 | site2.com        |            25 |      2 |       2 |
| 2012-06-16 00:11:30 | site3.com        |            12 |      3 |       2 |
| 2012-06-16 00:11:44 | site4.com        |             8 |      4 |       2 |
| 2012-06-16 00:11:51 | site5.com        |             2 |      5 |       2 |
| 2012-06-18 10:20:47 | site1.com        |           191 |      1 |       3 |
| 2012-06-18 10:20:52 | site2.com        |            25 |      2 |       3 |
| 2012-06-18 10:20:56 | site3.com        |            12 |      3 |       3 |
| 2012-06-18 10:21:00 | site4.com        |             8 |      4 |       3 |
| 2012-06-18 10:21:04 | site5.com        |             2 |      5 |       3 |
+---------------------+------------------+---------------+--------+---------+

I need to order the results in a Google Line Graph in the following manner:

['date', 'site1_entryID=1', 'site2_entryID=2', 'site3_entryID=3', (...)],";

The thing is that I'm having trouble managing the arrays that I generate. I'm using the following code:

mysql_connect("host_here", "username_here", "pass_here") or die(mysql_error());
mysql_select_db("my_database") or die(mysql_error());
$query = "SELECT * FROM pages";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

After this I need to echo the number of indexed_pages for each site where entryID = 1.

I don't know if this description is confusing or not, but I've tried pretty much everything and can't get the organize the data from the arrays to serve what I need to do. Help, please!

Thanks in advance!

like image 839
Haddock-san Avatar asked May 25 '26 13:05

Haddock-san


1 Answers

Don't use select *, that's lazy, and you're stuck accepting the fields in the order the DB decides to produce them in.

Specify the fields you want, in the order you want:

SELECT date, name, indexed_pages, etc...
like image 177
Marc B Avatar answered May 28 '26 05:05

Marc B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!