Forum Moderators: coopster

Message Too Old, No Replies

Supplied argument is not a valid MySQL result resource

Supplied argument is not a valid MySQL result resource

         

yollo

8:12 pm on May 12, 2003 (gmt 0)



When I try to search, I'm getting this message:
Supplied argument is not a valid MySQL result resource in /Library/WebServer/Documents/bosp/search_results.php on line 37

I have it set up like this:
$host="xx.xx.xx.xx";

$user = "user";

$password = "xxxx";

$dbname = "bosp";

$tablename = "spread";

$link = mysql_connect ($host, $user, $password);

$query = "SELECT * from $tablename where(sindex='$array[index]' or scase='$array[case]' or sorder='$array[order]')";

$result = mysql_db_query ($dbname, $query, $link);

// create table

print ("<table border=1 width=\"75%\" cellspacing=2 cellpadding=2 align=center>\n");

print ("<tr align=center valign=top>\n");

print ("<td align=center valign=top>Reference</td>\n");

print ("<td align=center valign=top>Case</td>\n");

print ("<td align=center valign=top>Order/Dispatch</td>\n");

print ("</tr>\n");

// fetch results

while ($row = mysql_fetch_array ($result)) {

print ("<tr align=center valign=top>\n");

print ("<td align=center valign=top>$row[index]</td>\n");

print ("<td align=center valign=top>$row[case]</td>\n");

print ("<td align=center valign=top>$row[order]</td>\n");

print ("</tr>");

}

mysql_close ($link);

print ("</table>\n");

?>

DrDoc

8:19 pm on May 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three things:

  • For the host, "localhost" is prefered (unless it's a remote server, of course)

  • Instead of this: $result = mysql_db_query ($dbname, $query, $link);
    Do this: $db = mysql_select_db($dbname);
    $result = mysql_query($query);

  • If you keep getting the message it means that you're trying to fetch rows even though the query didn't return any results. Either check your query to ensure that it always returns results, or add some sort of error control:

    if($result && mysql_num_rows($result)) {
    // fetch results
    }
    else {
    // no matches
    }

  • DrDoc

    8:20 pm on May 12, 2003 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Oh... and Welcome to Webmaster World! ;)

    jatar_k

    8:21 pm on May 12, 2003 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    Welcome ot WebmasterWorld yollo,

    would i be correct in assuming that this
    while ($row = mysql_fetch_array ($result))
    is line 37?

    I would guess that the query syntax is wrong. Do you try them through telnet/ssh first to ensure proper syntax? I think this

    SELECT * from $tablename where(sindex='$array[index]' or scase='$array[case]' or sorder='$array[order]')

    should be

    SELECT * from $tablename where sindex='$array[index]' or scase='$array[case]' or sorder='$array[order]'

    no parentheses around the where clause. Another tip is you can use this syntax

    $result = mysql_db_query($dbname,$query,$link) or die (mysql_errno().": ".mysql_error()."<BR>");

    it will show you the error from mysql if the query fails.

    <added>and what DrDoc said, it seems he's faster than me ;)