Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search mysql db problem

Status
Not open for further replies.

help120

Technical User
Apr 15, 2001
198
US
I'm having a problem with one of my scripts. Can you please take a look at it and give any hints on what I'm doing wrong.

--------------------------
The error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/virtual/site107/fst/var/ on line 41
number of Q&A found:
--------------------------

My database is lisathomaspayne_com and the table I'm tryn to search is phpbb_qa. phpbb_qa has 4 fields: id, ltptype, question and answer. I want the script to search all of the fields.


<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; align=&quot;center&quot;>
<tr>
<td align=&quot;left&quot; valign=&quot;middle&quot; class=&quot;tdupcom&quot;>Subscribers Home</td>
</tr>

<tr>
<td colspan=&quot;2&quot; align=&quot;left&quot; valign=&quot;top&quot; class=&quot;maincont&quot;>
<div align=&quot;right&quot;><img src=&quot;images/ltp_bullet2.gif&quot; alt=&quot;&quot; width=&quot;13&quot; height=&quot;12&quot; border=&quot;0&quot;> <a href=&quot;javascript:history.go(-1)&quot;>back</a></div>
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo &quot; You've not entered search details. Please go back and try again.&quot;;
exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

$host = '***';
$user = '***';
$pwd = '***';
$db = 'lisathomaspayne_com';
$db_table = 'phpbb_qa';
$conn = mysql_connect($host,$user,$pwd);

if (!$conn)
{
echo &quot;error: couldn't connect to database. Please try again later.&quot;;
exit;
}

mysql_select_db($db_table,$conn);
$query = &quot;select * from phpbb_qa where &quot;.$searchtype.&quot; like
'%&quot;.$searchterm.&quot;%'&quot;;
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo &quot;number of Q&A found: &quot;.$num_results.&quot;&quot;;

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo &quot;<p><strong>&quot;.($i+1).&quot;. Q: &quot;;
echo htmlspecialchars( stripslashes($row[&quot;id&quot;]));
echo &quot;</p>&quot;;
}

?>

</td>
</tr>
</table>
 
Your query is causing some kind of error your code does not trap.

Change this code section:
Code:
    $result = mysql_query($query);
    $num_results = mysql_num_rows($result);

to read:
Code:
    $result = mysql_query($query);
    if ($result == FALSE)
    {
       print mysql_error();
       exit;
    }
    $num_results = mysql_num_rows($result);

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top