Jump to content

2 Query of LIMIT [int, int] on one page, with 1st int auto change


y2yang

Recommended Posts

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:

 

<?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:

 

				<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>

 

 

Link to comment
Share on other sites

Wow, you just love to start a lot of topics don't you? What's wrong with the other topic you have opened for this problem?

 

Also, instead of having one query to limit 0, 4 and then another to limit 4,4, wouldn't it be the same as having it run from 0,8 in one query?

Link to comment
Share on other sites

You are totally right, only thing is I'm going to html it into two row of images, with 4 images on each row and a single dotted line in between the two row of images, and that's where the problem come in. How to implement that dotted line in between the tow row of images?

 

To get the two rows, I can just set it 0,8 and fetch it and my table would have arranged it nicely into 2 rows, but than I won't get that nice dotted line in between as well, so sad.

 

Here is what i'm talking about: vickizhao.net/starhome/photo/list.php

Link to comment
Share on other sites

$query = "SELECT * FROM thumb LIMIT 0,8";
$result =  mysql_query($query);

$count = 0;
while ($row = mysql_fetch_assoc($result)) {
      if ($count == 4) echo '-----------------------';
}

You can do something like that. That was an example. You can replace it with the HTML you have up there. I'm lazy and it's late here.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.