Jump to content

insert table as single cell per row


adi123

Recommended Posts

I am trying to insert data from a mysql in a table. I want the data to appear with the image on the left, item name on the top right followed by description underneath.

 

 

<?php

$sql = 'SELECT * FROM tbl_products ORDER BY id';

$result = $db->query($sql);

$output[] = '<ul>';

$output[] = '<table border="3" bordercolor="#000000">';

while ($row = $result->fetch()) {

 

$output[] = '<tr>';

$output[] = '<td><img src="images/'.$row['pic'].'" width="67" height="100" /></td>';

$output[] = '<td class="style10"><strong>'.$row['item_name'].'</strong></td>';

$output[] = '<td>'.$row['item_description'].'</td>';

$output[] = '</tr>';

 

}

$output[] = '</table>';

echo join('',$output);

?>

 

I would like the items to appear the same way as this page

 

http://aafcollection.info/items/list.php

Link to comment
https://forums.phpfreaks.com/topic/212665-insert-table-as-single-cell-per-row/
Share on other sites

Okay, what's actually your question?

 

One thing I do notice about your code at the moment is you're assigning each line of HTML to a new index in the array. Is that really necessary? Why not just build up a string and echo that...?

 

$output = '<ul>';
$output .= '<table border="3" bordercolor="#000000">';
while ($row = $result->fetch()) {

         $output .= '<tr>';
         $output .= '<td><img src="images/'.$row['pic'].'" width="67" height="100" /></td>';
         $output .= '<td class="style10"><strong>'.$row['item_name'].'</strong></td>';
         $output .= '<td>'.$row['item_description'].'</td>';
         $output .= '</tr>';

}
$output .= '</table>';
echo $output;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.