phatgreenbuds Posted September 28, 2007 Share Posted September 28, 2007 I think I have painted myself into a corner here. I would like to have the results of my query display in a grid format. The code below returns my thumbnails and links them to the actual images. However the entries in the database are simply paths to these images. I thought I could do this with CSS but the way this query is returning the results I am stuck and not sure how to resolve it. Any suggestions? <?php $query = "SELECT * FROM images"; $target = mysql_query($query); // uses the query variable defined above. confirm_query($target); // calls to the function file. while ($final_target = mysql_fetch_array($target)) { $submitter = "{$final_target["picsubmit"]}"; $description = "{$final_target["picdesc"]}"; echo "<a href='{$final_target['picpath']}' target='blank'><img src='{$final_target['tnpath']}'></a>"; echo "<div align=\"left\">" . $description . "<br>" . "</div>"; echo "<br>" . "Submitted By: " . $submitter; echo "<h4>" . "<hr>" . "</h4>"; echo "<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/ Share on other sites More sharing options...
pocobueno1388 Posted September 28, 2007 Share Posted September 28, 2007 There is a post about how to format your database output, I'm trying to find it. I'm pretty sure it's a sticky on one of the boards. Hold on, I will post it here in a few minutes hopefully once I find it. EDIT Okay...I know it is somewhere on these boards, I can't seem to find it. It's titled somthing like "DB results into rows". Does anyone else know what I'm talking about? This is a pretty common question, so I see people referencing to that post a lot. Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357314 Share on other sites More sharing options...
pocobueno1388 Posted September 28, 2007 Share Posted September 28, 2007 Here, this will give you rows of 5 <?php $query = "SELECT * FROM images"; $target = mysql_query($query); // uses the query variable defined above. confirm_query($target); // calls to the function file. echo '<table>'; $counter = 1; while ($final_target = mysql_fetch_array($target)) { $submitter = "{$final_target["picsubmit"]}"; $description = "{$final_target["picdesc"]}"; if ($counter == 5) { echo '<tr>'; $counter = 0; } echo "<td><a href='{$final_target['picpath']}' target='blank'><img src='{$final_target['tnpath']}'></a>"; echo "<div align=\"left\">" . $description . "<br>" . "</div>"; echo "<br>" . "Submitted By: " . $submitter; echo "<h4>" . "<hr>" . "</h4>"; echo "</td>"; $counter++; } echo '</table>'; ?> Hopefully I'm not confused on what your wanting... Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357330 Share on other sites More sharing options...
phatgreenbuds Posted September 28, 2007 Author Share Posted September 28, 2007 I promise I am not being lazy...I searched for it myself and have yet to find anything. Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357333 Share on other sites More sharing options...
sasa Posted September 28, 2007 Share Posted September 28, 2007 try <?php $query = "SELECT * FROM images"; $target = mysql_query($query); // uses the query variable defined above. confirm_query($target); // calls to the function file. while ($final_target = mysql_fetch_array($target)) { $submitter = "{$final_target["picsubmit"]}"; $description = "{$final_target["picdesc"]}"; echo '<div style="float:left;padding:10px;border:2px solid;margin-left:-2px;margin-top:-2px">': echo "<a href='{$final_target['picpath']}' target='blank'><img src='{$final_target['tnpath']}'></a>"; echo "<div align=\"left\">" . $description . "<br>" . "</div>"; echo "<br>" . "Submitted By: " . $submitter; //echo "<h4>" . "<hr>" . "</h4>"; echo "</div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357336 Share on other sites More sharing options...
phatgreenbuds Posted September 28, 2007 Author Share Posted September 28, 2007 pocobueno1388 that worked...thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357337 Share on other sites More sharing options...
phatgreenbuds Posted September 28, 2007 Author Share Posted September 28, 2007 SASA that worked as well with a couple small edit corrections...I think the was a : at the endo of a line that I had to change and add the closing div tag. but it works very well. thanks to you as well. Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357342 Share on other sites More sharing options...
rarebit Posted September 28, 2007 Share Posted September 28, 2007 tutorials: http://www.phpfreaks.com/tutorials.php pagination: http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php Code Library: http://www.phpfreaks.com/quickcode.php pagination: http://www.phpfreaks.com/quickcode_cats/33/Pagination.php PHP Freaks Forums > PHP and MySQL > FAQ/Code Snippet Repository: http://www.phpfreaks.com/forums/index.php/board,41.0.html column thing (at last!): http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357345 Share on other sites More sharing options...
phatgreenbuds Posted September 28, 2007 Author Share Posted September 28, 2007 Sweet...I now have this bookmarked. appreciate the help y'all. Quote Link to comment https://forums.phpfreaks.com/topic/71067-solved-ouput-formatting/#findComment-357349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.