Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

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

 Share

×
×
  • Create New...