Page 1 of 1

php mysql break after retreiving last db row

Posted: Sun Feb 08, 2015 2:00 pm
by cjkeane
hi everyone,
I'm struggling with getting inserting a break after retrieving the final row from the db. I've attached a screenshot as well so you can see the issue. There should be a simple fix for this. I have a 'clear: both' on the 'hr.style-two' and i even put an extra '<br clear="all" />' after the hr and that still doesn't push the next product picture to the next line. Any help would be appreciated. Thanks.

Code: Select all

<?php
	$string = "SELECT id,prod_name,prod_price,prod_dimensions,prod_paypalcode,filename1,filename2 FROM products ORDER BY prod_name ASC";
       	$query = mysql_query($string) or die (mysql_error());
       	$num_rows = mysql_num_rows($query);
	print "<div id='titles_smaller'>There are <b>$num_rows product(s)</b></div><br />";
	if($num_rows>0) {
		echo "<br />";
		$result = mysql_fetch_array($query);
		if($result==true) { 
			do { 
				echo "<div style='width:140px; float:left; margin-right: 30px; margin-bottom: 10px; '>";
				if (empty($result['filename1'])) { } else { ?> <a class="example-image-link" href=uploads/images/products/<?php echo $result['filename1']; ?> data-lightbox="example-1"><img class="example-image" src="uploads/images/products/<?php echo $result['filename1']; ?>" alt="thumb-1" style="height:160px;" /></a> <?php } ;
					echo "</div>";
					echo "<div style='width:140px; float:left; margin-right: 30px; margin-left: 30px; margin-bottom: 10px; '>";
					if (empty($result['filename2'])) { } else { ?> <a class="example-image-link" href=uploads/images/products/<?php echo $result['filename2']; ?> data-lightbox="example-1"><img class="example-image" src="uploads/images/products/<?php echo $result['filename2']; ?>" alt="thumb-1" style="height:160px;" /></a> <?php } ;
				echo "</div>";
				echo "<div style='width:140px; float:left; margin-right: 10px; margin-left: 20px; margin-bottom: 10px; ' class='clear'>";
				echo $result['prod_name'] . "<br />";
				echo $result['prod_price'] . "<br />";
				echo $result['prod_dimensions'] . "<br />";
				echo "<div style='width:140px; float:left; clear:both; margin-right: 30px; margin-bottom: 10px; ' >";
				echo $result['prod_paypalcode'] . "<br />";
				echo "<hr class='style-two'>";
				echo "<br clear='all' />";
				echo "</div>";
				echo "</div>";
			}
			while($result = mysql_fetch_array($query));
		}
	} else {
		echo "<div id='titles_smaller'>No products available.</div><br />";
	}                
?>

Re: php mysql break after retreiving last db row

Posted: Sat Feb 14, 2015 6:10 am
by phpRob
I don't like to see that you don't have an answer yet. You ask a tough question, at least for me because the needle is somewhere in that haystack but not easily visible. In a problem like this, I would copy all of your echo statement html and paste it into a text editor. Edit it so that you convert it into static html and then work with that html until you achieve the effect you want. No...better yet, right-click on the web page screen shot you gave us and select "view page source" so that you simply get all static html generated. Copy and paste all that static html into a text editor. Space it out so you can see the page structure better, indenting parent child tags, etc. Start to look at the problem from this angle. Iteratively edit and view the page until you get the effect you need. Cut away all peripheral, distracting html so you can focus on the crux of the problem. If you fail, post back with the smallest amount of html code that illustrates your problem. That's just a way I like to solve my issues like this--a sort of divide-and-conquer approach.

Re: php mysql break after retreiving last db row

Posted: Sat Feb 14, 2015 12:38 pm
by cjkeane
i've figured it out. it was just the position of my divs :)
phpRob wrote:I don't like to see that you don't have an answer yet. You ask a tough question, at least for me because the needle is somewhere in that haystack but not easily visible. In a problem like this, I would copy all of your echo statement html and paste it into a text editor. Edit it so that you convert it into static html and then work with that html until you achieve the effect you want. No...better yet, right-click on the web page screen shot you gave us and select "view page source" so that you simply get all static html generated. Copy and paste all that static html into a text editor. Space it out so you can see the page structure better, indenting parent child tags, etc. Start to look at the problem from this angle. Iteratively edit and view the page until you get the effect you need. Cut away all peripheral, distracting html so you can focus on the crux of the problem. If you fail, post back with the smallest amount of html code that illustrates your problem. That's just a way I like to solve my issues like this--a sort of divide-and-conquer approach.