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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning search results from a MySQL database

Status
Not open for further replies.

rskuse

Technical User
Jul 18, 2002
74
GB
Hello all,

I am using the following code to search results in a MySQL database table:

<table>

<?php
mysql_pconnect('localhost','root','');
mysql_select_db('gmarch_support');

$result = mysql_query(&quot;SELECT * FROM keyit WHERE comment LIKE '%{$_REQUEST['search']}%' order by company&quot;);

if(mysql_num_rows($result) == 0) {

echo 'Nothing found';

} else {

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

$akey = $row[0];
$company = $row[1];
$type = $row[2];
$web = $row[3];
$comment = $row[4];

echo &quot;<tr><td>$company</td></tr>&quot;;
echo &quot;<tr><td>$comment</td></tr>&quot;;


}
}
?>

</table>

It is returning the results fine but I was wondering how I return a set number of results eg. 10 per page.

Any help would be much appreciated, thankyou.

Rachel
 
using LIMIT:

$result = mysql_query(&quot;SELECT * FROM keyit WHERE comment LIKE '%{$_REQUEST['search']}%' order by company LIMIT 10&quot;); --------------------------------

jb
 
Thankyou jb,

I would also like to be able to search more than one field ie. the 'company' and 'type' fields aswell.

When I try 'WHERE comment OR company LIKE' it only searches the company field.

How do I accomplish this?

Rachel
 
like this:

WHERE comment LIKE '$var'OR company LIKE '$var' --------------------------------

jb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top