nadeemshafi9 Posted November 30, 2006 Share Posted November 30, 2006 hi guys i am trying to arange the items in my db as a grid i will show you what i have currently got its not too good lol.the first 3 items are printed nicley 3 across then the next line starts to farr from the left even thogh the mesurments are right.[code]<?php $accross = 0; $leftPos = 0; $topPos = 0; while($row = mysql_fetch_array($result)) { if($accross = 1) { $leftPos = 3; } if($accross = 2) { $leftPos = 6; } print "". "<div style='text-align: left; position: absolute; ". "left: " + leftPos + "cm; top: " + topPos + "cm; width: 2cm; height: 4cm;'>". "<img src='img.asp?id=" + $row["id"] + "' height='80px' width='80px'><br>". $row["name"] + "<br>". $row["type"] + "<br>". $row["description"] + "<br>". "</div>"; if($accross = 2) { $topPos = $topPos + 4; $leftPos = 0; } if($accross != 2){ $accross = $accross + 1; } }?>[/code]thanx for any help Link to comment https://forums.phpfreaks.com/topic/28946-construct-for-image-grid-css-php/ Share on other sites More sharing options...
bljepp69 Posted November 30, 2006 Share Posted November 30, 2006 Your logic is a bit out of whack. Once $accross is equal to 2, it won't increment any more. First iteration $accross = 0, second iteration $accross = 1, third iteration $accross = 2. From there on, $accross will always equal 2.More importantly, you are basically setting the value of $accross with each 'if' statement. If you are checking to see if $accross is equal to a value, you need to use if ($accross == 2). The statment if($accross = 2) simply returns true if it actually set $accross to the value of 2, which it always would.Try something like this...[code]<?php $accross = 0; $leftPos = 0; $topPos = 0; while($row = mysql_fetch_array($result)) { if($accross == 1) { $leftPos = 3; } if($accross == 2) { $leftPos = 6; } if($accross == 3) { $leftPos = 0; $topPos = $topPos + 4; $accross = 0; } print "". "<div style='text-align: left; position: absolute; ". "left: " + leftPos + "cm; top: " + topPos + "cm; width: 2cm; height: 4cm;'>". "<img src='img.asp?id=" + $row["id"] + "' height='80px' width='80px'><br>". $row["name"] + "<br>". $row["type"] + "<br>". $row["description"] + "<br>". "</div>"; $accross++; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/28946-construct-for-image-grid-css-php/#findComment-132603 Share on other sites More sharing options...
nadeemshafi9 Posted January 4, 2007 Author Share Posted January 4, 2007 LOL, i learnt tables are the way forward thanx thogh for your help Link to comment https://forums.phpfreaks.com/topic/28946-construct-for-image-grid-css-php/#findComment-152751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.