#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Quispamsis, NB, Canada
    Posts
    49
    Rep Power
    15
    Hey,
    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.

    Thanks,
    Scott Lee
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    You can always set a variable as 30, and make a for() loop to display the first 30 items.

    ex;
    $offset = 30;
    for($i=0;$i<$offset;$i++) {
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Quispamsis, NB, Canada
    Posts
    49
    Rep Power
    15
    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?

    Thanks,
    Scott
  6. #4
  7. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    depends what search method you are using

    are you searching a database?
    or each line of an array?
    or?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Quispamsis, NB, Canada
    Posts
    49
    Rep Power
    15
    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?

    Thanks,
    scott
  10. #6
  11. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    use mysql_num_rows()
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$total = mysql_num_rows($mysql_result);[/code]
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    15
    SELECT Count(*) as ttl

    Then $ttl will give you the count.

    ------------------
    From the day we're born, we're running out of time.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Quispamsis, NB, Canada
    Posts
    49
    Rep Power
    15
    That is only giving me the number of results on that page....It still won't get the total results.
  16. #9
  17. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    then execute two queries, one with the limit, one without
  18. #10
  19. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<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:

    <?

    $limit=30;

    $total_query=mysql_query("select * from yourtblname where someconditions");
    //get the total results

    $total_results=mysql_num_rows($total_query);
    //get the total number.

    $second_query=mysql_query("select * from yourtblname where someconditions LIMIT $offset,$limit");
    //get some range of values..

    $start_result=$offset+1;
    //record display starting from

    $end_result=$offset+$limit;
    //record display ending at

    if ($end_result>$total_results){
    //the display number exeding more than total record no.
    //so make that last record
    $end_result=$total_results;
    }


    if (mysql_num_rows($second_query)>0){

    echo "search results $start_result-$end_result of $total_results";
    // here display that values..


    }else{
    echo "No resultsn";
    }
    ?>


    you should pass $offset through your url.

    Good Luck!!

    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited August 22, 2000).]

Similar Threads

  1. Cgi Search feature script
    By butsy_7 in forum Perl Programming
    Replies: 5
    Last Post: January 22nd, 2004, 07:43 PM
  2. How can I perform a search with a previous search results?
    By charlie_tango in forum MySQL Help
    Replies: 1
    Last Post: January 17th, 2004, 10:06 AM
  3. search results errors!
    By clue05 in forum PHP Development
    Replies: 2
    Last Post: January 16th, 2004, 11:18 AM
  4. Using sessions for search / results pages
    By Quirk in forum PHP Development
    Replies: 10
    Last Post: December 15th, 2003, 08:36 PM
  5. Google search results
    By webwonderuk in forum Search Engine Optimization
    Replies: 5
    Last Post: November 28th, 2003, 02:25 AM

IMN logo majestic logo threadwatch logo seochat tools logo