![]() |
foreach statement?
Alright so I am looking to create a foreach statement using mysql query. I am not sure how I can do this seeing as how it requires an array_expression and value.
Here's my code: PHP Code:
Thanks, Randy |
Quote:
1. ORDER BY DESC ID is not a valid statement, ORDER BY ID DESC would be 2. $results = 'mysql_query($query)'; should be$results = mysql_query($query); without the single quotes. Then what you need to do is add this code: PHP Code:
|
My Code:
PHP Code:
Quote:
Database Structure Looks Like This: ![]() Values Look Like: ![]() ------------------ I tried changing it to ID, description, name, everything and it gives me the same thing. Any thoughts? |
PHP Code:
The reason that "mysql_fetch_array()" was not working is because it accepts two arguments (2nd is optional but recommended): $result - The MySQL query... $type - How you want the data back, numeric or assoc. $data[0] vs $data['name'] E.G. mysql_fetch_array($query, MYSQL_ASSOC); |
Code:
PHP Code:
Warning: Invalid argument supplied for foreach() in C:\wamp\www\pbird\index.php on line 20 line 20 is the foreach statement |
The problem is that you can't loop over a mysql resource, you must have the array assignment before the loop otherwise there is nothing to loop over.
Whats wrong with the good ol' while loop, eh? PHP Code:
PHP Code:
|
Thanks to both of you its working now with sketchMedia's first code.
Much appreciated. |
| All times are GMT. The time now is 05:58 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0