Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    2

    Question Unanswered: Adding to a limit?

    Hi, what I am trying to do is add to a limit, for example:

    Code:
    select <variables go here> from <table goes here> order by <variable> desc limit 0,5
    then later on in the script I want to add 1 to the maximum limit, so in this case, add 1 to the limit of 5 making it 6. Is this possible?

  2. #2
    Join Date
    Dec 2002
    Location
    California
    Posts
    32
    If you are using php you can use a statement like the following:
    PHP Code:
    <?php
    $limitvar 
    5;
    $result mysql_query("select <variables go here> from <table goes here> order by <variable> desc limit $limitvar")
        or die(
    "Invalid query: " mysql_error());
    ?>
    Then you can either put a loop in or anything else you might want. If you want to incrament by on in the code and rerun the query you can use:
    PHP Code:
    <?php 
    $limitvar 
    5;
    function 
    runmyqry() {
        
    $result mysql_query("select <variables go here> from <table goes here> order by <variable> desc limit $limitvar")
        or die(
    "Invalid query: " mysql_error());
    }
    Then when you want to call and run the funtion:
    PHP Code:
    $limitvar++
    runmyqry
    Hope This Helps!!

  3. #3
    Join Date
    Aug 2003
    Posts
    2
    It does help a lot, thankyou, but I still have some problems. Let me explain what I am doing.

    I am using phpnuke (hold the bashing please ) I am trying to make a script that shows the last 5 articles, and i did this. One of the variables it uses is $secid and that is the section id (eg the category of the articles) but I want it to exclude a certain secid and not list it, but list the others. so basically act like that secid was never there. This is what I have now:

    PHP Code:
    <?php

    /////////////////Get the Globabls/////////////////

    global $prefix$dbi$language$multilingual;

    /////////////////////////////////////////////////

    $limitvar == "0,5";
    /////////////////The runmyqry function//////////

    function runmyqry() {
        
    $result sql_query("select artid, secid, title, content, slanguage from ".$prefix."_seccont order by artid desc limit $limitvar"$dbi);
        }

    /////////////////////////////////////////////////


    /////////////////If the secid is 4...////////////

        
    if ($secid == "4") {
                    
    $limitvar++
                    
    runmyqry;
    }

    /////////////////////////////////////////////////


    /////////////////List the data//////////////////
            
    while(list($artid$secid$title$content$slanguage) = sql_fetch_array($result$dbi)) {
            
    $result2 sql_query("select secid, secname from ".$prefix."_sections where secid='$secid'"$dbi);
            list(
    $secid$secname) = sql_fetch_row($result2$dbi);
            if (
    $secid == "4") {
            echo 
    "";
            }
            else {
            echo 
    "<STRONG><BIG></BIG></STRONG><a href=\"modules.php?name=Sections&op=viewarticle&artid=$artid\">$title</a> - ($secname)<br>";
            }
    /////////////////////////////////////////////////


    }
    ?>
    Right now the error I get is a parse error on line 23, line 23 is the following:

    PHP Code:
    21                 if ($secid == "4") {
    22                 $limitvar++
    23                 runmyqry;
    24                 
    Help?...
    Last edited by DiZASTiX; 08-29-03 at 11:28.

  4. #4
    Join Date
    Dec 2002
    Location
    California
    Posts
    32

    It should be

    This is what those lines should look like:
    PHP Code:
    1                 if ($secid == "4") {
    22                 $limitvar++; //This is where the error was look carefully its an easy one to miss!
    23                 runmyqry;
    24                 
    Hope that helps if it doesn't email me here

Posting Permissions

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