| while loop produces errors in db data retrieval
|
surrealillusions

msg:4496266 | 2:14 pm on Sep 17, 2012 (gmt 0) | Having a bit of trouble in getting data from a couple of custom database tables. This error is produced: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in <url> on line 19
$qry = "SELECT * FROM wp_customtable"; $data = mysql_query($qry); while($row = mysql_fetch_array($data,MYSQL_ASSOC)) { // a whole bunch of stuff dealing with the data }
Trying a foreach loop doesnt produce any errors, but also produces no data. I've tried numerous bits of code from around the code but with no success. How do you get the while loop to work within wordpress? All this code is within a custom page template, no plugins used for this.
|
lorax

msg:4496442 | 10:21 pm on Sep 17, 2012 (gmt 0) | Silly question but did you connect to the database yet?
|
surrealillusions

msg:4496868 | 3:27 pm on Sep 18, 2012 (gmt 0) | Yep. I get data if I use a foreach statement, With the while loop there, no data is displayed and I get that error. Any reason why the while loop produces an error and the foreach statement is fine?
|
lorax

msg:4497529 | 10:39 pm on Sep 19, 2012 (gmt 0) | No good reason that I can think of but I haven't dug into the details of your code. In your opening post you said you didn't get data. Now you do? I am not aware of any particular reason the while loop wouldn't run. SO... troubleshooting time. What happens if you remove the while statement and simply try to output the number of rows returned or the data from a single row?
|
|
|