LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-10-2004, 09:08 AM   #1
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Rep: Reputation: 30
php links to search pages method


I am creating a program that will produce search results from a mysql database using php. The search will have 10 results per page. I am looking for methods that will create the links to different pages of the same search the very same was LinuxQuestions does in their forums. Here is the basic search code.
Thank you

// the database is already open and
// the database is selected
function simple_search($searchType)
{
$query=mysql_query("SELECT * FROM item WHERE itemType='$searchType'"); //or die("(".mysql_errno().") Error:".mysql_error());

if(!$num_rows=mysql_num_rows($query)){ // see if there are any results
print "<h2>Sorry there are no results from your search</h2>";
}else{
$num_rows=mysql_num_rows($query); //or die("(".mysql_errno().") Error:".mysql_error());
print "<h2>There are $num_rows results from your search</h2>";
get_page_string($num_rows); // here is where I want to call the function to get the string to link to the other pages
print "<table width=\"100%\" align=\"center\" border=1>\n";
while($a_row=mysql_fetch_row($query))
{
print "<tr>$a_row</tr>";

}

print "</table><br>\n";
return;
}
}
 
Old 01-10-2004, 09:25 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You usually just use an offset value - to get the number of pages just divide the total number of rows by 10. Then each link looks like:
<A href="search.php?search=word&page=1">1</A> <A href="search.php?search=word&page=2">2</A>

Then in your code you print rows starting at "($page*10)-10" up to "$page*10".

So page 2 would print matches 10 through to 19.
 
Old 01-10-2004, 10:50 AM   #3
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
That seems very easy. Hmm sometimes the answer is so obvious. I will post again if there is a problem.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search engine for for you docs and home web pages caulfiek Linux - Software 5 11-29-2005 08:12 AM
reading pages of threads after a search rblampain LQ Suggestions & Feedback 4 11-16-2005 09:49 PM
Search all man pages for a phrase suguru Linux - Software 1 09-12-2004 06:38 AM
Better method for a php search engine? Pcghost Programming 4 02-18-2004 12:44 PM
Search and replace links xtrude Linux - Newbie 4 01-29-2003 11:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration