homepage Welcome to WebmasterWorld Guest from 54.242.231.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
mysql_fetch_array error using LIKE
not a valid MySQL result resource
UnikRasu




msg:1256103
 8:26 pm on Dec 3, 2002 (gmt 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

 

steffan




msg:1256104
 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]

jatar_k




msg:1256105
 9:06 pm on Dec 3, 2002 (gmt 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());

cyberax




msg:1256106
 10:41 am on Dec 5, 2002 (gmt 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.

jatar_k




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

it's the db

mysql_db_query -- Send a MySQL query
Description
resource mysql_db_query ( string database, string query [, resource link_identifier])

cyberax




msg:1256108
 7:59 pm on Dec 5, 2002 (gmt 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?

andreasfriedrich




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

It should be indeed. mysql_db_query requires at least two parameter.

transistor




msg:1256110
 5:48 am on Dec 6, 2002 (gmt 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";
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved