SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am doing a limit by select query but want to also know the actual number of results there would be if it wastn't limited. So bascially, i want say the 20 links between 20 and 40 but also want to know there are 93 links that satisfy the condition. Can i do this or do i need to do a seperate count query as well?

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could either have a separate query or grab all of the results and then only use results 20-40 in your script.

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You could do two things.....first is get the the number of rows:

    $select1 = mysql_query("SELECT * FROM table LIMIT 20");
    $select2 = mysql_query("SELECT COUNT(*) as number FROM table");
    $number = $select2["number"];

    Or you could limit in your script:

    $select1 = mysql_query("SELECT * FROM table");
    while ($result = mysql_fetch_array($select1)) {
    $arr[] = array(
    "DateAdded" => $result["DateAdded"],
    "Name" => $result["Name"])
    }
    }
    $number = count($arr);

    // LATER print variables like:

    reset($arr);
    foreach($arr as $key => $val) {
    $i = 1;
    $date = $arr[$key]["dateAdded"];
    $name = $newsdata[$key]["Name"];

    if ($i < 20) {
    print $Name;
    print "<br>$date";

    $i++;
    }
    }

    ?>


    Hope this helps,
    Peter

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it did, i went for the count option, i think it will be more efficient here, also read that the count query will be cached by the database so will not use up much resources to get it.

    thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •