SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using Limit in my queries

    Problem Solved Thanks to Everyone who Helped

    Last edited by tnrstudios; Jul 29, 2005 at 18:49.

  2. #2
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query  "SELECT category FROM stuff_emotions WHERE $cat = 'category' LIMIT $limitvalue$limit"

  3. #3
    SitePoint Enthusiast Gonik's Avatar
    Join Date
    May 2005
    Location
    Thessaloniki, Greece
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something obvious like adding quotes around category?

    Try this:
    PHP Code:
     $query  "SELECT category FROM stuff_emotions WHERE $cat = 'category' LIMIT $limitvalue$limit"
    edit: darn, a little too late
    Don't Drink & Surf The Net

  4. #4
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried both examples and neither worked

  5. #5
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then most likely one of your variables is blank? Try echoing out the query before running the query to see if the correct variable is being passed.

    Silly

  6. #6
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this helps but here's the rest of the script:

    PHP Code:
        @mysql_select_db("tnrstudi_emotions") or die("ERROR--CAN'T CONNECT TO DB"); 

        
    $limit          12;                
        
    $query_count "SELECT * FROM stuff_emotions"
        
    $result_count   mysql_query($query_count);     
        
    $totalrows      mysql_num_rows($result_count); 

        if(empty(
    $page)){ 
            
    $page 1
        } 
             

        
    $limitvalue $page $limit - ($limit); 
        
    $query  "SELECT category FROM stuff_emotions WHERE $cat = 'category' LIMIT $limitvalue$limit";         
        
    $result mysql_query($query) or die("Error: " mysql_error()); 

        if(
    mysql_num_rows($result) == 0){ 
            echo(
    "Nothing to Display!"); 
        } 

        
    $bgcolor "#E0E0E0"// light gray 
        
    $counter "1"

        echo(
    "<table cellspacing=3 cellpadding=5><tr>"); 
         
        while(
    $row mysql_fetch_array($result)){ 
            if (
    $bgcolor == "#FFFFFF"){ 
                
    $bgcolor "#FFFFFF"
            }else{ 
                
    $bgcolor "#FFFFFF"
            } 
            if (
    $row["category"] == $cat)
                {
        
    $counter += 1;
        echo(
    "<td bgcolor=".$bgcolor."><TABLE><TR><TD height=125 width=125>"); 
        echo(
    "<a href=show.php?id=");
         echo(
    $row["id"]); 
       echo(
    "><img border=0 src=http://www.messenger-stuff.com/files/");
        echo(
    $row["type"]); 
        echo(
    "/");
        echo(
    $row["category"]); 
        echo(
    "/");
        echo(
    $row["filename"]); 
        
        echo(
    "></a><BR><p>"); 
        echo(
    $row["filename"]); 
        echo(
    "<BR><i>"); 
        echo(
    $row["size"]); 
        echo(
    " bytes</i></p></TD></TR></TABLE></TD>"); 
            if (
    $counter == "4"){
                echo 
    "</TR><TR>";
                
    $counter "1";  }
        } 
    }
        echo(
    "</tr></table>"); 

        if(
    $page != 1){ 
    $pageprev $page -1
             
            echo(
    "<a href=\"$PHP_SELF?page=$pageprev\">PREVIOUS PAGE</a> "); 
        }else{ 
    echo(
    "PREV".$limit."&nbsp;"); 
        } 

        
    $numofpages $totalrows $limit
         
        for(
    $i 1$i <= $numofpages$i++){ 
            if(
    $i == $page){ 
                echo(
    $i." "); 
            }else{ 
                echo(
    "<a href=\"$PHP_SELF?page=$i&cat=$cat\">$i</a> "); 
            } 
        } 


    if((
    $totalrows - ($limit $page)) >= 0){ 
            if(
    $i == $page){ 
                echo(
    $i." "); 
            }else{ 
                echo(
    "<a href=\"$PHP_SELF?page=$i&cat=$cat\">$i</a> "); 
            } 
        } 

        if((
    $totalrows - ($limit $page)) > 0){ 
    $pagenext $page +1;           
            echo(
    "<a href=\"$PHP_SELF?page=$pagenext&cat=$cat\">NEXT PAGE</a>"); 
        }else{ 
            echo(
    "NEXT".$limit); 
        } 
         
        
    mysql_free_result($result); 

    ?> 

  7. #7
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I echoed the query beforehand and it was filled (it is defined by the url anyways ie: page.php?cat=abstract )

    And I have the database full of entries where category = abstract so I don't know whats up!

    EDIT: I am now getting:
    Code:
    Error: Unknown column 'abstract' in 'where clause'
    with this query:

    PHP Code:
        $query  "SELECT * FROM stuff_emotions WHERE $cat = category LIMIT $limitvalue$limit"

  8. #8
    SitePoint Enthusiast Gonik's Avatar
    Join Date
    May 2005
    Location
    Thessaloniki, Greece
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query  "SELECT * FROM stuff_emotions WHERE category = '$cat' LIMIT $limitvalue$limit"
    Don't Drink & Surf The Net

  9. #9
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using Gonik's example, I changed the query to:

    PHP Code:
        $query  "SELECT * FROM stuff_emotions WHERE category = '$cat LIMIT $limitvalue$limit'"
    And now the script works except for it is returning nothing :O

  10. #10
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query  "SELECT category FROM stuff_emotions WHERE category = '$cat' LIMIT $limitvalue$limit"

  11. #11
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ya that is returning the same thing freakysid

  12. #12
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo out the value of $query and then cut and paste it into an SQL query and see what result you get (either using mysql from the shell or phpMyAdmin).

  13. #13
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it working when i used:

    PHP Code:
                         $query "SELECT category FROM stuff_emotions where category = '".$cat."'"
    But when I added the limit statement:

    PHP Code:
                         $query "SELECT category FROM stuff_emotions where category = '".$cat."' category = 'ategory LIMIT $limitvalue$limit'""; 
    It didn't return anything!

  14. #14
    SitePoint Member Marlboro_Man's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    PHP Code:
     $query "
     SELECT category 
     FROM stuff_emotions 
     WHERE category = '"
    .$cat."' 
     LIMIT 
    $limitvalue$limit 
     "

    regards

  15. #15
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you keep using the wrong SQL even when other's have posted it correctly so many times.
    Code:
    $query  = "SELECT category FROM stuff_emotions WHERE `category` = '$cat' LIMIT $limitvalue, $limit";
    echo $query;
    Use that to replace what you have right now. And if it doesn't work, please paste the query echoed in your page so that we can figure out what's wrong.

  16. #16
    Steve Benjamins tnrstudios's Avatar
    Join Date
    Jun 2003
    Location
    canada
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem is Fixed thanks to all who helped


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
  •