Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIMIT in SELECT not working as planned

Status
Not open for further replies.

CadMonkey

Programmer
Nov 26, 2003
4
GB
Using a defined start point for the rows and an offset.

The script only returns 11 when I requested 12. I know I have more than 11. I tried the SELECT query in phpMyAdmin it works fine so it must be somehting to do with the way I'm using the code. I can't spot it. Can anybody have a read through and see if you can spot it?

Thanks

Code:
<?php
$dbh=mysql_connect (&quot;computer&quot;, &quot;database&quot;, &quot;password&quot;)
or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db (&quot;dbname&quot;);


$lolimitbase = 0;
$offset = 12;

$lolimit = 1;

if ($pageno > 1) {
$lolimit = ($pageno -1 ) * $offset;
}

echo &quot;$lolimit&quot;;

$query = &quot;SELECT * FROM image_tb ORDER BY date_up DESC LIMIT $lolimit,$offset&quot;;
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);

$counter = 1;

while ($row = mysql_fetch_array($result))
{
$imgname = $row[img]name[/img];
$imgurl = $row[url];
$imglarge = $row[large_link];
$imgdate = $row[date_up];

if ($counter == 1) {
echo &quot;<body bgcolor='#000000' text='#000000'>&quot;;
echo &quot;<table width='650' border='0' cellpadding='1' cellspacing='10' bgcolor='#000000' bordercolor='#000000'>&quot;;
echo &quot;<tr bordercolor='#000000'>&quot;;
}

// Normal code
echo &quot;<td height='140' valign='middle' align='center' bgcolor='#FFFFFF'>&quot;;
echo &quot;<div align='center'>&quot;;
echo 	&quot;<a href='/$imglarge'&quot;;
echo 		&quot;target='_blank'>&quot;;
echo 		&quot;<img src='/$imgurl'&quot;;
echo 		&quot;width='133'&quot;;
echo		&quot;height='100'&quot;;
echo 		&quot;border='0'>&quot;;
echo 	&quot;</a>&quot;;
echo 	&quot;<br>&quot;;
echo &quot;<font face='Verdana, Arial, Helvetica, sans-serif' size='1'>$imgname</font>&quot;;
echo &quot;</div>&quot;;
echo &quot;</td>&quot;;

if ($counter == 4) {
echo &quot;</tr>&quot;;
echo &quot;<tr bordercolor='#999999'>&quot;;
}

if ($counter == 8) {
echo &quot;</tr>&quot;;
echo &quot;<tr bordercolor='#999999'>&quot;;
}

if ($counter == 12) {
echo &quot;</tr>&quot;;
echo &quot;</table>&quot;;
break;
}

$counter++;

}

echo &quot;</tr>&quot;;
echo &quot;</table>&quot;;

?>
 
Code:
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);

$counter = 1;
Remove the second line. You are fetching the first line from the result set without ever using it.

//Daniel
 
You spotted it, many many thanks.

Especially for the quick reply!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top