Re: DB query returning wierd results
| From: | Steve Edberg | Date: | Thu, 08 Aug 2002 17:29:36 +0000 |
| Subject: | Re: DB query returning wierd results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111686@lists.php.net to get a copy of this message | ||
At 12:56 PM -0400 8/8/02, Brian V Bonini wrote:
Can anyone see a reason why the following would skip the first row of the DB? <?phpYes I see the reason :) Why are you doing this fetch_object()? If fetch_object operates anything like mysql_fetch_array() (which I usually use), it advances the result set pointer after the fetch. So here you fetch the first row into $content and - at least in this code snippet - proceed to ignore it. As programs often do, it's doing just what you asked...which MAY not be what you want! -steve$sql = "SELECT * FROM SlideShow";$result = mysql_query_check($sql); $content = mysql_fetch_object($result);
$i=0; while($row = mysql_fetch_object($result)) { $img = $row->image_name;-- +------------------------------------------------------------------------+ | Steve Edberg sbedberg@ucdavis.edu | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +------------------------------------------------------------------------+ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | +------------------------------------------------------------------------+$size = getimagesize("thumbnails/" . $img); $popupSize = getimagesize("images/" . $img); $popupWidth = (50+($popupSize[0])); $popupHeight = (250+($popupSize[1])); if (($i % 4) == 0) echo "<tr align=\"center\">\n";echo <<<ENDJS <td> <a href="#" onclick="popup('./?id=$row->id','ig','width=$popupWidth,height=$popupHeight, toolbar=no,scrollbars=yes,resizable=yes,location=no');"> <img src="/ss/thumbnails/$img" $size[3] alt="click to enlarge" /></a><br />$popupSize[0] x $popupSize[1] </td> ENDJS;echo "\n"; $i++; if (($i % 4) == 0) echo "</tr>\n";} ?>