need help with a limit query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dsick
Forum Commoner
Posts: 57
Joined: Fri Mar 27, 2009 3:34 pm

need help with a limit query

Post by dsick »

Aight, with this design i got here i have 5 tiers, each tier needs to be in its own column so i used a table for that, the query is off a lil bit tho... each tier shows 11 records from the database....
Image


here im starting from row 0(1) and showing 11 records.. this is the query for tier 1

Code: Select all

<?php
$query = mysql_query("SELECT * FROM cats  LIMIT 0,11 ") 
or die(mysql_error());  
while($row = mysql_fetch_array( $query ))  {
 
 
$job = $row['title'];
 
 
echo "<a href=\"jobs.php?jobtype=$job\">"; 
echo $row['title'];
 
echo "</a>";
 echo"<Br/>";
 }?>

this is tier 2's query... starting from row 12 and showing 11 records from database

Code: Select all

<?php
$query = mysql_query("SELECT * FROM cats ORDER BY title LIMIT 12,11 ") 
or die(mysql_error());  
while($row = mysql_fetch_array( $query ))  {
echo "<a href=\"jobs.php?jobtype=$job\">"; 
echo $row['title'];
 
echo "</a>";
 echo"<Br/>";
 }?>
tier 3 starting from row 22 and showing 11 records

Code: Select all

        <?php
$query = mysql_query("SELECT * FROM cats  LIMIT 22,11 ") 
or die(mysql_error());  
while($row = mysql_fetch_array( $query ))  {
echo "<a href=\"jobs.php?jobtype=$job\">"; 
echo $row['title'];
 
echo "</a>";
 echo"<Br/>";
 }?>

tier 4.. starting from row 32 and showing 11 records

Code: Select all

            <?php
$query = mysql_query("SELECT * FROM cats  LIMIT 32,11 ") 
or die(mysql_error());  
while($row = mysql_fetch_array( $query ))  {
echo "<a href=\"jobs.php?jobtype=$job\">"; 
echo $row['title'];
 
echo "</a>";
 echo"<Br/>";
 }?>

tier 5, starting from row 43 and showing 11 records

Code: Select all

        <?php
$query = mysql_query("SELECT * FROM cats  LIMIT 43,11 ") 
or die(mysql_error());  
while($row = mysql_fetch_array( $query ))  {
echo "<a href=\"jobs.php?jobtype=$job\">"; 
echo $row['title'];
 
echo "</a>";
 echo"<Br/>";
 }?>
all is well in the tier one query, but as soon as i click on a tier 2, tier 3, tier 4, tier 5 item they all show the last record from tier one in the $_Get which was XML, so every tier after tier one is linking to XML...

and i realize this all needs to be pushed up into one function but i need to figure out how to get this working first....
woahtuff
Forum Newbie
Posts: 4
Joined: Wed Aug 26, 2009 10:36 pm

Re: need help with a limit query

Post by woahtuff »

I think it's because you only assign a value to $job in tier 1, the last row in tier 1 is the last time $job was assigned a value, so when you use $job in the following tiers, it uses the last value given to it in tier 1.

add $job = $row['title']; to the following tiers, just like the first one.
dsick
Forum Commoner
Posts: 57
Joined: Fri Mar 27, 2009 3:34 pm

Re: need help with a limit query

Post by dsick »

yea your right i didnt even see that.. its kind of overriding every tier from tier 1.. good eye :lol:

its working now.. cant believe i missed that... been trying to figure it out for like an hour haha
Post Reply