Re: First record not diplaying

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2008-12-22 at 14:14 +0000, Gary Maddock-Greene wrote:

> Ash ... this is the full code block ... I am really new to php so I 
> appreciate your tip
> 
> <?php
> // Good to go
> 
> if (0 == $totalRows_rsSearch) {
> echo "<h3>Sorry no products were found</h3>";
> } else {
> echo "<h3>Please click on a product for further information.</h3>";
> while ($row_rsSearch = mysql_fetch_assoc($rsSearch)){
> echo "<div class=\"productitem\"><img src=\"products".
> $row_rsSearch['product_image']."\">
>        <div class=\"text\">
>          <h3>". $row_rsSearch['product_name']."</h3>
>            <p class=\"style1\">". $row_rsSearch['product_subtitle'] ."
> </p>
>            <a href=\"products". $row_rsSearch['product_url']."\">View
> Product</a>
>          <div class=\"clear\"></div>
>          </div> <div class=\"clear\"></div>
>       <center>
>          </center>
>        </div>";
> }
> 
> }
> ?>
> 
> -- 
> - Gary Maddock-Greene
> "Ashley Sheridan" <ash@xxxxxxxxxxxxxxxxxxxx> wrote in message 
> news:1229955502.3530.3.camel@xxxxxxxxxxxxxxxxxxxxxxxx
> > On Mon, 2008-12-22 at 14:02 +0000, Gary Maddock-Greene wrote:
> >> Hi, I seem to have a bug in my code but can't see why. My first record 
> >> does
> >> not display when I run a search. Can anyone spot what I have done wrong?
> >> Thanks
> >>
> >> if (0 == $totalRows_rsSearch) {
> >> echo "<h3>Sorry no products were found</h3>";
> >> } else {
> >> echo "<h3>Please click on a product for further information.</h3>";
> >> while ($row_rsSearch = mysql_fetch_assoc($rsSearch)){
> >> echo "<div class=\"productitem\"><img src=\"products".
> >> $row_rsSearch['product_image']."\">
> >>
> >> - Gary Maddock-Greene
> >>
> >>
> > You seem to be missing quite a lot of code from your example, namely the
> > ending quotation mark, ending semicolon, the ending brace to the while
> > loop, the closing </div> tag inside the loop...
> >
> > Also (and I know the speed junkies will want to shoot me now!) you could
> > shorten the echo inside the while loop to:
> >
> > echo "<div class=\"productitem\"><img src=
> > \"products{$row_rsSearch['product_image']}\">";
> >
> >
> >
> >
> > Ash
> > www.ashleysheridan.co.uk
> > 
> 
> 

I've redone the code as best as I could without knowing where it fits in
with anything else just now. I've always found that keeping to a decent
indenting practise can help removing a lot of bugs like these.

<?php
// Good to go

if (0 == $totalRows_rsSearch)
{
	echo "<h3>Sorry no products were found</h3>";
}
else
{
	echo "<h3>Please click on a product for further information.</h3>";
	while ($row_rsSearch = mysql_fetch_assoc($rsSearch))
	{
		print <<<EOP
		<div class="productitem">
			<img src="products{$row_rsSearch['product_image']}">
     		<div class=\"text\">
			<h3>{$row_rsSearch['product_name']}</h3>
			<p class="style1">{$row_rsSearch['product_subtitle']}</p>
			<a href="products{$row_rsSearch['product_url']}">View Product</a>
			<div class="clear"/>
		</div>
		<div class="clear"/>
EOP;
	}
}
?>

Note, you're best off copying the code from the email that comes
straight to you from me, rather than the mailing list one, as the
mailing list will put line breaks in at bad points!


Ash
www.ashleysheridan.co.uk

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux