Jump to content


Photo

MySQL Error


  • Please log in to reply
7 replies to this topic

#1 Matt L

Matt L

    Young Padawan

  • Members
  • Pip
  • 272 posts
  • Gender:Male
  • Location:Newcastle

Posted 12 August 2006 - 01:15 PM

Right, I'm making a tutorial cataloguing system and I'm on to the Latest Tutorial section that will go on the side of the page.
latesttut.php
<?php
include('dbconnect.php');
$query = mysql_query("SELECT * tutorials ORDER BY id DESC WHERE validate='1' LIMIT 10");
while ($latest = mysql_fetch_array($query)) {
	$link = $latest['tutorial'];
	$title = $latest['title'];
		echo("<a href='$link'>$title</a>");
	}
?>
That's the code I've got (without the HTML)
And I keep getting this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/djl2k/public_html/latesttut.php on line 12


Line 12 is the mysql_fetch_array() comes in.

#2 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 12 August 2006 - 01:22 PM

I swear, im gonna go spare lol. Just kiddin.

Please remember this though:

Always add error reporting to ALL queries! that means change
$query = mysql_query("SELECT * tutorials ORDER BY id DESC WHERE validate='1' LIMIT 10");
to
$query = @mysql_query("SELECT * tutorials ORDER BY id DESC WHERE validate='1' LIMIT 10") or die(mysql_error());

Try that, and it will tell you what is wrong with the query instead of outputting an ugly error. Post back with the new error which will enable me or someone else to help you much more or you may even be able to solve the problem yourself. (its a helpful little message lol)

Edited by .Matt, 12 August 2006 - 01:26 PM.


#3 cheerio

cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 12 August 2006 - 01:34 PM

SELECT * FROM tutorials

#4 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 12 August 2006 - 01:49 PM

LOL!!! I missed that, Thanks cheerio.

Im gonna go lay down in shame now. My point still is valid though.

Edited by .Matt, 12 August 2006 - 01:49 PM.


#5 Matt L

Matt L

    Young Padawan

  • Members
  • Pip
  • 272 posts
  • Gender:Male
  • Location:Newcastle

Posted 12 August 2006 - 02:26 PM

Yeah, I've got that now, but I can't figure out how to fix the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE validate='1' LIMIT 10' at line 1


The whole mysql query:
SELECT * FROM tutorials ORDER BY id DESC WHERE validate='1' LIMIT 10

Edited by DJL2K, 12 August 2006 - 02:26 PM.


#6 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 12 August 2006 - 02:37 PM

try this:

SELECT * FROM `tutorials` WHERE validate = '1' ORDER BY id DESC LIMIT 10


#7 Matt L

Matt L

    Young Padawan

  • Members
  • Pip
  • 272 posts
  • Gender:Male
  • Location:Newcastle

Posted 12 August 2006 - 03:27 PM

Thanks, thats worked. I suppose it's in a logical order now.

#8 cheerio

cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 12 August 2006 - 03:36 PM

heh, same problem twice :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users