selliottsxm Posted May 7, 2014 Share Posted May 7, 2014 I'm trying to display the results of a query in a table. The query returns graphic file names so that I can display images in a table. I'm trying to display them so that there are four images in one row, but all I get is one per row. Does anyone know what I might try? My script is below: <?php# feeds_user.php This script will advertise the feeds on the index.php page (page for non members)require_once ('../mysqli_connect.php');$q= "SELECT feed_id, feed_graphic AS graphic FROM feeds_user ORDER By feed_id";$r= @mysqli_query ($dbc, $q);while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)){echo '<table align="center" cellspacing="0" cellpaddin g="5" border="10" width="1100px"><tr> . <td align="center" colspan="4"><a href="join.php"><img src="'. $row['graphic'] .'"></a></td></tr>';}echo'</table>';?> Link to comment Share on other sites More sharing options...
HartleySan Posted May 7, 2014 Share Posted May 7, 2014 Put four tds within one tr. Link to comment Share on other sites More sharing options...
selliottsxm Posted May 7, 2014 Author Share Posted May 7, 2014 I tried that one already. All it does is give me the same graphic four times in one row Link to comment Share on other sites More sharing options...
HartleySan Posted May 7, 2014 Share Posted May 7, 2014 Because your while loop is not set up correctly. Something like the following should get you there: $i = 0; while (something) { if ($i % 4 === 0) { // echo tr start tag. } // echo td tag with img. if ($i % 4 === 0) { // echo tr end tag. } $i++; } Better than that solution though, you could just use CSS to set the td widths to 25%, or even better than that, you could not use a table at all (tables are for tabular data!), and instead used an unordered list or just images that are either floated left or have the inline-block display property. That all make sense? Link to comment Share on other sites More sharing options...
selliottsxm Posted May 7, 2014 Author Share Posted May 7, 2014 I started fooling around with the incrementing variable $i It's getting there. Now I have 8 images in each row (each one appearing twice) Link to comment Share on other sites More sharing options...
HartleySan Posted May 7, 2014 Share Posted May 7, 2014 Like I said, the $i incrementer is the least ideal option. You're better off rewriting your CSS/HTML to make everything more semantic. Link to comment Share on other sites More sharing options...
Recommended Posts