unitedintruth Posted December 24, 2008 Share Posted December 24, 2008 I have a mysql table written for images. The fields are id, image, title, comment. I am needing to write a table that will lay the images in a page 3 wide and I am having trouble getting them to layout. I can get the data to lay out one image wide but not 3. I understand I do this with an "i" variable but have no idea how to lay this out and can't find a tutorial for this anywhere on the web. Can someone please help me with this? Thanks, Donnie Link to comment https://forums.phpfreaks.com/topic/138330-solved-layout-help/ Share on other sites More sharing options...
Sakesaru Posted December 24, 2008 Share Posted December 24, 2008 echo '<div style="display:block;">'; while ($results = mysql reading thing here) { echo '<img src="'.$results['imgname'].'" style="display:inline;">'; } echo '</div>'; Should do it, or you could use a table. Link to comment https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723297 Share on other sites More sharing options...
unitedintruth Posted December 24, 2008 Author Share Posted December 24, 2008 Considering I am very new to PHP and just learning, this is what I have now. <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM puppies WHERE approved='yes'"); echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td width=\"150\" align=\"center\"><img src=\"http://www.americanmi-kiregistryassociation.com/images/puppy_pics/" . $row['photo'] . "\"><br />"; echo "Date of Birth: " . $row['dob'] . "<br />"; echo "Date Available: " . $row['doa'] . "<br />"; echo "Puppy Number: " . $row['nbr'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> The table fields had to change some to fit my needs. I need to make this read 3 wide rather than 1. Thanks, Donnie Link to comment https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723302 Share on other sites More sharing options...
Sakesaru Posted December 24, 2008 Share Posted December 24, 2008 You mean like this? (see attached image) [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723306 Share on other sites More sharing options...
unitedintruth Posted December 24, 2008 Author Share Posted December 24, 2008 Yes, but with the other fields showing below each image. Link to comment https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723315 Share on other sites More sharing options...
Sakesaru Posted December 24, 2008 Share Posted December 24, 2008 echo '<table style="border:1px solid black;"><tr>'; // don't use "<table border="1"> use CSS for that. $count = 1; while($row = mysql_fetch_array($result)) { echo '<td style="width:150px; align:center;"><img src="http://www.americanmi-kiregistryassociation.com/images/puppy_pics/' . $row['photo'] . '"><br />'; // again swapped out width="150" align="center" for CSS echo "Date of Birth: " . $row['dob'] . "<br />"; echo "Date Available: " . $row['doa'] . "<br />"; echo "Puppy Number: " . $row['nbr'] . "</td>"; /* Just a simple loop to count which column we're on, if we're on the third, we need to end the row and reset our count back to 1 for the next row. */ if($count==3) { echo "</tr><tr>"; $count=1; } else { $count++; // does the same thing as $count = $count + 1; } } echo "</tr></table>"; Merry Christmas. Link to comment https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723343 Share on other sites More sharing options...
unitedintruth Posted December 24, 2008 Author Share Posted December 24, 2008 Perfect solution, that worked great, thank you very much. Thanks, Donnie Link to comment https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.