i think need some advanced help with a search script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

i think need some advanced help with a search script

Post by chris12295 »

many search engines have a thing where u can click on a number to jump ahead. I was wondering what i should add to make that work for me. I think it has somthing to do with limit. PLEASE HELP!!! :?

here is my code:

Code: Select all

<?
$page += 1;
$tempCount = $page*10;
$old+=10;
trim($searchBy);
mysql_connect("localhost");
mysql_select_db("Ads");
$query1="select * from user_Ads where $searchBy like '%$keywords%'";
$results1=mysql_query($query1);
$query = "select * from user_Ads where $searchBy like '%$keywords%' order by $searchBy desc limit $old,$numResultsPP";
$result = mysql_query($query);
$num_results = mysql_num_rows($results1);
$number_cols = mysql_num_fields($result);

if($num_results==0)&#123;
			echo "<table bgcolor=#e1e1e1><tr><td>Your search for <b>$keywords</b> returned <b>0</b> results.</td></tr></table>";

		&#125;
else &#123;
echo "<table bgcolor=#e1e1e1><tr><td>Your search for <b>$keywords</b> returned <b>$num_results</b> results.</td></tr></table>\n\n";
echo "<br><form name=form1 action=$PHP_SELF method=post>\n<input type='hidden' name='resultCount' value=$tempCount>\n<input type='hidden' name='page' value=$page><input type='hidden' name='searchBy' value=$searchBy>\n<input type='hidden' name='old' value=$old>\n<input type='hidden' name='numResultsPP' value=$numResultsPP>\n<input type='hidden' name='keywords' value=$keywords>\n";
if($num_results>=1 && $num_results - ($page * 10) > 0 && $page!=1)&#123; 
echo "<a href='javascript:history.go(-1)'><--Prev</a>";

echo "<a href='javascript:document.form1.submit()'>Next--></a>\n</form><br>\n";	
&#125;
elseif($num_results>=1 && $num_results - ($page*10) <= 0) &#123;
echo "<a href='javascript:history.go(-1)'><--Prev</a></form>\n";
&#125;
else&#123;
echo "<a href='javascript:document.form1.submit()'>Next--></a>\n</form>\n";
&#125;
&#125;

while ($row = mysql_fetch_row($result)) &#123;
$resultCount += 1;
echo "<table border=0 width=900 cellpadding=0 cellspacing=0>\n";


	for($i=0;$i<$number_cols;$i++)&#123;
echo "<tr><td bgcolor='#004080'><center><span style='color:#ffffff;width:100%'><b>Part:</b>$row&#1111;7] $row&#1111;9] $row&#1111;8]--><b>Category:</b> $row&#1111;6]</span></center></td></tr>";
		echo "<tr bgcolor=#e1e1e1>\n";
echo "<td>";
		echo "<b>$resultCount</b>. $row&#1111;2], $row&#1111;1]<blockquote>$row&#1111;10]<br><b>E-mail:</b> <a href='mailto:$row&#1111;3]'>$row&#1111;3]</a><br><b>Phone:</b> $row&#1111;4] <b>Fax:</b> $row&#1111;5]<br>";
$i = 11;
echo "</td>\n";
echo "</tr>\n";

	&#125;

echo "</table>";
echo "<br><br>";
&#125;
?>
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Database pagination

Post by BDKR »

Limit is a big key in what you're talking about. The format is "limit n, m" where n is starting record or row and m is the number of rows from the start you want returned.

As for saying where it goes in your code, that's a little tough as there are numerous approaches to dealing with this and my approach may break something that allready works. I created an Class that does this for me. Howevr, there are others that think that method is over the top.

Anyways, there is an article on the topic over at PHPBuilder and a great discussion assoctiated with it as well. Also, if you are interested in using a class, check out Eclipse Library for PHP. It's the best out there in my opinion. Anyways, the query object should provide you with what you need along these lines.

Later on,
Big Din K.R.
Post Reply