I'm trying to create a system wherein the users can view records in the database, and its corresponding image. My problem is how to present the table in a fashion similar to that of ebay:
Here's my code:
<?php
require_once('header.php');
?>
<?php $list_items = $db->get_results("SELECT * FROM tbl_products"); ?>
<table border="1">
<?php foreach($list_items as $k=>$li){ ?>
<tr>
<td>
<p>
<img src="../img/items/<?php echo $li->str_filename; ?>" width="150px" height="150px">
</p>
<p>
Product Name: <?php echo $li->str_productName; ?>
</p>
<开发者_运维问答p>
Category: <?php echo $li->str_category; ?>
</p>
<p>
Quantity: <?php echo $li->dbl_qty; ?>
</p>
<p>
Price: <?php echo $li->dbl_price; ?>
</p>
</td>
</tr>
<?php } ?>
</table>
The current code is outputting the records in list view. Wherein, there's only one record per row. What I want is 4-6 records per row. How do I do that?
try this
<table border="1">
<?php
$intMaxColumn=4;
$intCountColumn=1;
foreach($list_items as $k=>$li){
if($intCountColumn==1){
?>
<tr>
<?php
}
?>
<td>
<p>
<img src="../img/items/<?php echo $li->str_filename; ?>" width="150px" height="150px">
</p>
<p>
Product Name: <?php echo $li->str_productName; ?>
</p>
<p>
Category: <?php echo $li->str_category; ?>
</p>
<p>
Quantity: <?php echo $li->dbl_qty; ?>
</p>
<p>
Price: <?php echo $li->dbl_price; ?>
</p>
</td>
<?php
if($intCountColumn==$intMaxColumn){
$intCountColumn=1;
?>
</tr>
<?php
}else{
$intCountColumn++;
}
}
?>
</table>
add CSS to these tables:
float:left;
and it will be the same
and do not include one table, but new table for each item. Try this
<?php
require_once('header.php');
$list_items = $db->get_results("SELECT * FROM tbl_products");
foreach($list_items as $k=>$li){
?>
<table border="1" style="float:left;">
<tr>
<td>
<p>
<img src="../img/items/<?php echo $li->str_filename; ?>" width="150px" height="150px">
</p>
<p>
Product Name: <?php echo $li->str_productName; ?>
</p>
<p>
Category: <?php echo $li->str_category; ?>
</p>
<p>
Quantity: <?php echo $li->dbl_qty; ?>
</p>
<p>
Price: <?php echo $li->dbl_price; ?>
</p>
</td>
</tr>
</table>
<?php } ?>
demo
精彩评论