Welcome to WebmasterWorld Guest from 23.21.38.201

Forum Moderators: coopster & jatar k

mysql_fetch_array error using LIKE

not a valid MySQL result resource

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

10+ Year Member



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)



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)

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



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)

10+ Year Member



"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)

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



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)

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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

10+ Year Member



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";
}
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month