Welcome to WebmasterWorld Guest from 23.22.182.29

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

mysql_fetch_array error using LIKE

not a valid MySQL result resource

     
8:26 pm on Dec 3, 2002 (gmt 0)

New User

10+ Year Member

joined:Dec 3, 2002
posts:23
votes: 0


i get this message
mysql_fetch_array(): supplied argument is not a valid MySQL result resource

when i try to run this file

<html>
<?php

$open = mysql_connect("localhost");

$data = mysql_db_query("video1, SELECT * FROM video1 WHERE namn LIKE 'sok' ORDER BY namn");

while ($rad = mysql_fetch_array ($data)) {

print "<B>";
print $rad["namn"];
print "nummer";
print $rad["nummer"];
print "</B><BR>";
print "Tid:";
print $rad["tid"];
print "<P>";

}

?>
</html>

is there anybody who knows whats wrong pleas help me

8:38 pm on Dec 3, 2002 (gmt 0)

New User

joined:June 26, 2011
posts:
votes: 0


I recon the error's with the: LIKE 'sok'
Change it to: LIKE '%sok%' and see if it works! :)

[edited by: jatar_k at 8:52 pm (utc) on Dec. 3, 2002]
[edit reason] no sigs please [/edit]

9:06 pm on Dec 3, 2002 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


Welcome to WebmasterWorld [webmasterworld.com] UnikRasu and steffan

the like won't match anything as steffan mentioned, if there is no variable part of the match it will work just like equals.

take a look at String Comparison Functions [mysql.com]

you could also try to add an or die [php.net] to your query to get the error from mysql.

like so
$data = mysql_db_query($somequery) or die(mysql_error());

10:41 am on Dec 5, 2002 (gmt 0)

New User

10+ Year Member

joined:Aug 22, 2002
posts:38
votes: 0


"video1, SELECT * FROM video1 WHERE namn LIKE 'sok' ORDER BY namn"

What does the "video1," before the SELECT do? I've never written a query like that before.

7:41 pm on Dec 5, 2002 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


it's the db

mysql_db_query -- Send a MySQL query
Description
resource mysql_db_query ( string database, string query [, resource link_identifier])
7:59 pm on Dec 5, 2002 (gmt 0)

New User

10+ Year Member

joined:Aug 22, 2002
posts:38
votes: 0


in that case, shouldn't it be:

mysql_db_query("video1", "SELECT * FROM video1 WHERE namn LIKE 'sok' ORDER BY namn");

instead of:

mysql_db_query("video1, SELECT * FROM video1 WHERE namn LIKE 'sok' ORDER BY namn");

which is what he is doing... perhaps this is why it is causing a mysql error?

8:09 pm on Dec 5, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


It should be indeed. mysql_db_query requires at least two parameter.
5:48 am on Dec 6, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:May 2, 2002
posts:141
votes: 0


Usually when I get
mysql_fetch_array(): supplied argument is not a valid MySQL result resource
it means that the result is empty.
Try:

$result = mysql_query("select * from db where field like '$somevar'");
if (mysql_numrows($result)>0) {
echo stuff;
} else {
echo "No results";
}