Page 1 of 1
mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 12:29 am
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
Re: mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 3:12 am
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.
Re: mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 3:43 am
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.
Re: mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 4:57 am
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.
Re: mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 5:07 am
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.
Re: mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 7:31 am
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
Re: mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 9:06 am
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)) {
Re: mysql_fetch_array() Help Please
Posted: Sun Oct 04, 2009 9:16 am
by lipun4u
that was silly mistake buddy...