mysql_fetch_array() Help Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michaelpeerman
Forum Newbie
Posts: 2
Joined: Sun Oct 04, 2009 12:26 am

mysql_fetch_array() Help Please

Post by michaelpeerman »

This is what i get

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tsmonkey/public_html/1337board.co.cc/thread.php on line 182
Heres what is on line 182

Code: Select all

for($i=0;$post=mysql_fetch_array($posts);$i++){
Please tell me whats wrong
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql_fetch_array() Help Please

Post by requinix »

What's wrong is you didn't post the entire chunk of code that deals with whatever it's doing and instead only posted one line.
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: mysql_fetch_array() Help Please

Post by Griven »

What he posted is fine.

When something is not a valid MySQL resource, that means there's been an error in your query--something's not right.

Check your query again and make sure it's not throwing an error.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql_fetch_array() Help Please

Post by requinix »

Griven wrote:What he posted is fine.

When something is not a valid MySQL resource, that means there's been an error in your query--something's not right.

Check your query again and make sure it's not throwing an error.
Could also be that the query was never executed. Wouldn't be the first time I've seen someone try

Code: Select all

$posts="SELECT * FROM table";
for($i=0;$post=mysql_fetch_array($posts);$i++){
Thus I asked for more code: to see the problem rather than just guess at the solution.
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: mysql_fetch_array() Help Please

Post by Griven »

tasairis wrote:Thus I asked for more code: to see the problem rather than just guess at the solution.
... but I like guessing games. :)

He's right--make sure you're actually executing the query as well.
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: mysql_fetch_array() Help Please

Post by lipun4u »

Code: Select all

$posts="SELECT * FROM table";
$result = mysql_query($sql);  
while ($data = mysql_fetch_row($result)) {
hope..above code will help u
jmaker
Forum Newbie
Posts: 16
Joined: Tue May 21, 2002 11:13 pm

Re: mysql_fetch_array() Help Please

Post by jmaker »

Why do you have your sql statement assigned to $posts, and then the variable $sql being passed to the function? Try this.

Code: Select all

 
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
while ($data = mysql_fetch_row($result)) {
 
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: mysql_fetch_array() Help Please

Post by lipun4u »

that was silly mistake buddy...
Post Reply