Jump to content


MYSQL error: Warning: mysql_fetch_array():


6 replies to this topic

#1 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 14 November 2005 - 11:00 PM

I am trying for the first time making my own PHP/MySQL site from scratch, and I have this error from trying to display results. It looks like I have it correct in all my guide/how-to books, but reguardless, I am getting this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/fabiann/public_html/ninja/index.php on line 165

Here is my php on the page(I just took the php for there was far too much html to shift through. line 165 is the 7th line in the php) :
<?php
//call DB connection
require('../../ninjadbconnect.php');

$result = @mysql_query("SELECT * FROM ninja_events ORDER BY id DESC LIMIT 5");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $row['id'];
$when = $row['date'];
$where = $row['where'];
$what = $row['what'];
echo "<tr><td class=\"eventinfo\">$id</td><td class=\"eventinfo\">$date</td><td class=\"eventinfo\">$where</td><td class=\"eventinfo\">$what</td></tr>";
}
?>

Anyone got a clue of whats going on?

Edited by FabianN, 15 November 2005 - 12:52 AM.


#2 Blitz

    Jedi In Training

  • Twodded Staff
  • PipPip
  • 307 posts
  • Location:California
  • Interests:Php, html, css, etc, band, trumpet, anime, my dog, TV, computers, video games, sleeping, marching band, sleeping, jazz, sleeping, metal, sleeping, classic rock, sleeping, music, jazz band, did I mention sleeping?, kicking the hell out of kids that won't take the time to spell or use proper grammar, my website, etc.

Posted 15 November 2005 - 12:26 AM

From the code I see, you haven't even defined the $select variable that you're using in the mysql_fetch_array(). Try

mysql_fetch_array($result, MYSQL_ASSOC)

Edited by Blitz, 15 November 2005 - 12:26 AM.


#3 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 15 November 2005 - 12:52 AM

Ah dammit. Thats not the problem, I know. I was testing around with "exactly" what guides were telling me and gave up kinda half-way through one of them and decided to post. Must have not changed the varible back.

I've double and triple checked the original code and made sure all varibles are correct now. I edited above to fit.

#4 Stu

    Retired P2L Staff

  • Publishing Betazoids
  • PipPipPipPip
  • 1,761 posts
  • Gender:Male

Posted 15 November 2005 - 04:24 AM

are you positive your dbconnect file is 2 subfolders beneath ?

require('../../ninjadbconnect.php');

possibly try linking to a full url instead i dont know...

include 'http://www.heh.com/ninjadbconnect.php';

just clutching at straws.

#5 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 15 November 2005 - 06:04 AM

if i am right the error you are getting means that there is a lil problem with ur SQL and nothing is getting selected.

Quote

SELECT * FROM `ninja_events` ORDER BY `id` DESC LIMIT 5

that should work

#6 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 15 November 2005 - 01:14 PM

I just figured it out, and I feel like the dumbest person on the planet.

I had the MySQL user permissions set-up wrong.

>_<

#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 15 November 2005 - 04:10 PM

To prevent further errors with mysql_fetch_array, you should make all your mysql_query()'s look ruffly like the following.
$result = mysql_query("THE QUERY") or die(mysql_error());
Note, no @ and the "or die" part.

Either that or set up some kind of fancy class/custom function so you don't have to type "or die" five thousand times.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users