Jump to content

Echoing SQL Results - Odd outcome..


dragon2309

Recommended Posts

Hey there everyone, I've been playing with PHP and SQL for a few years, mainly as a hobby, so I'm not an expert, and it takes me a while to get most things working. This has me stumped... I'm pretty sure (like 80% sure) that it was working fine, then I just noticed the bug and have no idea how to fix it..

 

I run an SQL query, that when run in the db returns 6 records, all 6 records are to be echoed to the page as per this loop:

 

 $i = 1;

 while ($row = $result->fetch()) {

 if ($i <= 3) {
  $output[] = '<div id="featuredinner">';

  $output[] = "\n";

  $output[] = '<a href="images/'.$row['img'].'_lrg.jpg" rel="lightbox" title="'.$row['desc'].'"><img src="images/'.$row['img'].'_lrg.jpg" width=150px /></a><br />'."\n".' '.$row['title'].' - <strong>£'.$row['price'].'</strong><br /> <a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a>';
  $output[] = "</div>\n        ";
  } else {
   $output[] = '<br /><br /><br />';
   $i = 0;
   }
  $i++;
 }

 

I use the same loops on multiple other pages echoing records from the same table (just with different credentials) and they seem to be workign fine. It's jsut this one.. The bug is that the 4th record is never returned, 1, 2 and 3 are echoed on one line as desired, then its ment to drop a line and echo 4, 5 and 6, it doesnt, all i get is 5 and 6 and then a blank space.

 

Ideas?? As said the exact same piece of code for the loop and if statement is used on other pages (different product categroies) perfectly, the only difference is that the other sections have more items in, (some have 18-19 things in that are echoed on page 3 per line perfectly fine..

 

Page is live at http://www.thechocolatehut.co.uk/truf_milk.php if you want to see, ignore the DQL query being echoed to apge, I wanted to see what query the page was generating.

 

Thanks all, Dave.

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.