August 21st, 2000, 11:10 AM
I am making a search engine and I'm not quite sure how to make it count search results. I show 30 per page and would like to to be able to say something like "search results 1-30 of 72" with 72 being the total search results found for that keyword. If anyone can help it would be greatly apprechiated.
August 21st, 2000, 12:19 PM
You can always set a variable as 30, and make a for() loop to display the first 30 items.
$offset = 30;
display results line by line
echo "<a href='phpfile.php?offset=$offset&end=$total'>Last $offset-72 matches</a>";
Use this code as a guideline only, cause I can assure you it won't work out-of-the-box. :P
To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson
August 21st, 2000, 09:20 PM
72 was just an example, the actual results could be anything....Does anyone have or know anywhere where i could see how to get the total number of search results?
August 21st, 2000, 09:35 PM
depends what search method you are using
are you searching a database?
or each line of an array?
August 21st, 2000, 10:38 PM
I have a table called "mp3"
and i am searching through that. I was told this would work but it doesn't:
$total = count($mysql_result);
any ideas what i can do?
August 21st, 2000, 11:11 PM
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$total = mysql_num_rows($mysql_result);[/code]
August 21st, 2000, 11:29 PM
SELECT Count(*) as ttl
Then $ttl will give you the count.
From the day we're born, we're running out of time.
August 22nd, 2000, 12:11 AM
That is only giving me the number of results on that page....It still won't get the total results.
August 22nd, 2000, 01:38 AM
then execute two queries, one with the limit, one without
August 22nd, 2000, 05:37 AM
<<That is only giving me the number of results on that page....It still won't get the total results.>>
<<then execute two queries, one with the limit, one without>>
Try something like following:
$total_query=mysql_query("select * from yourtblname where someconditions");
//get the total results
//get the total number.
$second_query=mysql_query("select * from yourtblname where someconditions LIMIT $offset,$limit");
//get some range of values..
//record display starting from
//record display ending at
//the display number exeding more than total record no.
//so make that last record
echo "search results $start_result-$end_result of $total_results";
// here display that values..
echo "No resultsn";
you should pass $offset through your url.
www.jobxyz.com-IT Career Portal
"The fear of the LORD is the beginning of knowledge..."
[This message has been edited by Shiju Rajan (edited August 22, 2000).]