Jump to content


This is driving me nuts.


5 replies to this topic

#1 ian mullen

    Young Padawan

  • Members
  • Pip
  • 22 posts
  • Location:UK
  • Interests:Television, Computers, Internet.

Posted 15 March 2008 - 03:28 PM

$sql = mysql_query("SELECT * FROM $cat WHERE surname LIKE \"%$az%\" ORDER BY surname");
while($list = mysql_fetch_array($sql))

This keeps producing the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in *location* on line 15

Does anybody have any ideas? This is driving me nuts.

Thanks all.

Edited by VisitEureka.net, 15 March 2008 - 03:29 PM.


#2 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 15 March 2008 - 03:48 PM

Why is the table name a variable?

It should look something like this: (Not tested so I don't know if it would work)

SELECT * FROM table_name WHERE cat = '$cat' AND surname LIKE \"%$az%\" ORDER BY surname

Now I could be wrong about it so please correct me. Are there multiple tables that you are selecting from where you would need the name to be a variable? Because I would think that "$cat" would be for a row. So if "cat" is a row you would want to use the WHERE cat = '$cat' AND ... (Make sure you change "cat" to whatever the row really is called)

dEcade

#3 ian mullen

    Young Padawan

  • Members
  • Pip
  • 22 posts
  • Location:UK
  • Interests:Television, Computers, Internet.

Posted 15 March 2008 - 04:24 PM

No, the '$cat' is the table name. Basically the address will be:

index.php?cat=actors&av=j

I want the table name to be selected based upon what is typed in the address, so if it is cat=characters, it will search through the characters table.

Does that make sense?

#4 ian mullen

    Young Padawan

  • Members
  • Pip
  • 22 posts
  • Location:UK
  • Interests:Television, Computers, Internet.

Posted 15 March 2008 - 04:36 PM

This might help. I tried the mysql_error (never knew about that before).

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 ''actors' WHERE surname LIKE "%h%" ORDER BY surname' at line 1

Basically it is putting the actors and the h where they should be, but it is not working :S

Edited by VisitEureka.net, 15 March 2008 - 04:37 PM.


#5 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 15 March 2008 - 04:41 PM

That error usually means there is something wrong with your query, I'm pretty sure it has something to do with $cat like dEcade mentioned. Try this
 	$sql = mysql_query("SELECT * FROM $cat WHERE surname LIKE \"%$az%\" ORDER BY surname") or die(mysql_error());
to see wich error you get.

The $cat variable will probably not be filled out so my guess is, you'll need to do something like:

 	$sql = mysql_query("SELECT * FROM ". $cat . " WHERE surname LIKE '%" . $az . "%' ORDER BY surname");



B

#6 ian mullen

    Young Padawan

  • Members
  • Pip
  • 22 posts
  • Location:UK
  • Interests:Television, Computers, Internet.

Posted 15 March 2008 - 04:47 PM

Dude, thank you! The first one worked because it showed me the error. I'm basically a moron. I left my old database name in instead of putting the new name. It was looking at the wrong database. I feel like such an idiot now.

$sql = mysql_query("SELECT * FROM $cat WHERE surname LIKE \"%$az%\" ORDER BY surname") or die(mysql_error());






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users