zero-perfoliate
zero-perfoliate

Author Topic: 2 Query of LIMIT [int, int] on one page, with 1st int auto change  (Read 300 times)

Offline y2yang

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
I am running two query with LIMIT on the same page, which I pulled from my MySQL with field id.

$query = "SELECT * FROM thumb LIMIT 0, 4";
and
$query = "SELECT * FROM thumb LIMIT 4, 4";

Would it be possible to have this programmed to change automatically with page id.

Example, on ?id=1, it would have the above query but on ?id=2, it would run a query like the one below.

$query = "SELECT * FROM thumb LIMIT 8, 4";
and
$query = "SELECT * FROM thumb LIMIT 12, 4";


To put it simple:

First query on ?id=1 would start pulling data from row 1 to 4 and the second query on ?id=1 to start pulling data from row 5 to row 8.

While query 1 on ?id=2 start pulling data from row 9 to row 12 and query 2 on ?id=2 from row 13 to row 16.

Here is example of code:

Code: [Select]
<?php
// database connection info

$query "SELECT * FROM thumb LIMIT 0, 4";
$result =  mysql_query($query);
while (
$row mysql_fetch_assoc($result)) {
?>

   <div style="width:132px;height:132px;margin:0 5px 0 5px;float:left;">
        <table width="132" style="background:url('http://image.vickizhao.net/starhome/photo/list/img_pic_bg.gif') no-repeat;">
        <tr style="height:132px;">
            <td><a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/read/read.php?Pid=<?php print $row['id']; ?>"><img id="reSizeImg1" src="<?php print $row['imgpath']; ?>" style="border:solid 1px #ffffff;" alt=""  /></a></td>
        </tr>
        </table>
    </div>
<?php
}
?>


            <div style="clear:left;overflow:hidden;width:0;height:0;"></div>
             <p style="margin:20px;"></p>
            <div class="dotHLine1"></div>
            <p style="margin:20px;"></p>
               
<?php
$query 
"SELECT * FROM thumb LIMIT 4, 4";
$result =  mysql_query($query);
while (
$row mysql_fetch_assoc($result)) {
?>

   <div style="width:132px;height:132px;margin:0 5px 0 5px;float:left;">
        <table width="132" style="background:url('http://image.vickizhao.net/starhome/photo/list/img_pic_bg.gif') no-repeat;">
        <tr style="height:132px;">
            <td><a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/read/read.php?Pid=<?php print $row['id']; ?>"><img id="reSizeImg1" src="<?php print $row['imgpath']; ?>" style="border:solid 1px #ffffff;" alt=""  /></a></td>
        </tr>
        </table>
    </div>
<?php
}
?>

The main reason why I wanted to perform 2 LIMIT on one page is that I wanted 8 images to show on one page with a dotted line in between my two row of image.

The code to go between the 2 row of images is:

Code: [Select]
            <div style="clear:left;overflow:hidden;width:0;height:0;"></div>
             <p style="margin:20px;"></p>
            <div class="dotHLine1"></div>
            <p style="margin:20px;"></p>

The reason I just didn't do LIMIT 0, 8 is because I wanted a dotted line in between the two rows:
1 2 3 4
-------
5 6 7 8

But I don't know how to get it there, yet.

 

zero-perfoliate