homepage Welcome to WebmasterWorld Guest from 54.224.53.192
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
while loop produces errors in db data retrieval
surrealillusions

5+ Year Member



 
Msg#: 4496264 posted 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

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4496264 posted 10:21 pm on Sep 17, 2012 (gmt 0)

Silly question but did you connect to the database yet?

surrealillusions

5+ Year Member



 
Msg#: 4496264 posted 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

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4496264 posted 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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved