我试图在一个动态生成的表格中显示我从数据库中获得的图像,该表格将连续显示3列图像
"Image1 Image 2 Image 3
Image 4 Image 5 Image 6
etc"
以下是我现在的代码:
<?php
$dynamicList = "";
while( $row = sqlsrv_fetch_array($stmt))
{
$rownumber = $row['rownumber'];
$end_at = $items_on_page + $start_from;
if (($rownumber>$start_from)&&($rownumber<=$end_at))
{
$prod_id = $row['productID'];
$cat_id = $row['catalogueID'];
$col_id1 = $row['colour1'];
$col_id2 = $row['colour2'];
$col_id3 = $row['colour3'];
$sql3 = "SELECT * FROM product_colours WHERE colourID =? OR colourID =? OR colourID =?";
$params3 = array($col_id1,$col_id2,$col_id3);
$stmt3 = sqlsrv_query( $conn, $sql3, $params3);
$count = 1;
while( $row3 = sqlsrv_fetch_array( $stmt3))
{
switch ($count)
{
case 1:$colour1 = $row3['colour_description'];break;
case 2:$colour2 = $row3['colour_description'];break;
case 3:$colour3 = $row3['colour_description'];break;
}
$count++;
}
$sql3 = "SELECT catalogueID, product_name, product_price, description FROM product_catalogue WHERE catalogueID = ?";
$params3 = array($cat_id);
$stmt3 = sqlsrv_query( $conn, $sql3, $params3);
$columncount = 0;
$dynamicList = '<table width="744" border="0" cellpadding="6"><tr>';
while( $row3 = sqlsrv_fetch_array( $stmt3))
{
$prod_name = $row3['product_name'];
$prod_price = $row3['product_price'];
$prod_desc = $row3['description'];
$dynamicList .= '<td width="135"><a href="product_details_women.php?productID=' . $prod_id . '">
<img src="images/products/Small/Women/' . $prod_id . '.jpg" alt="' . $prod_name . '" width="129" height="169" border="0">
</a>
</td>
<td width="593" valign="top">' . $prod_name . '<br>
£' . $prod_price . '<br>
<a href="product_details_women.php?productID=' . $prod_id . '">View Product Details</a></td>';
if($columncount == 2)
{
$dynamicList .= '</tr><tr>';
$columncount = 0;
}
else
{
$columncount++;
}
}
$dynamicList .= '</tr></table>';
echo $dynamicList;
}
}
?>
但由于某种原因,图像一直只显示在一列中。我希望能够以每行3列显示它们。我尝试将所有代码放在while循环中,但这不起作用
答案 0 :(得分:0)
$dynamicList = '<table width="744" border="0" cellpadding="6">';
while( $row3 = sqlsrv_fetch_array( $stmt3))
{
$prod_name = $row3['product_name'];
$prod_price = $row3['product_price'];
$prod_desc = $row3['description'];
$dynamicList .= '<tr><td width="135"><a href="product_details_women.php?productID=' . $prod_id . '"><img src="images/products/Small/Women/' . $prod_id . '.jpg" alt="' . $prod_name . '" width="129" height="169" border="0"></a></td><td width="593" valign="top">' . $prod_name . '<br> £' . $prod_price . '<br><a href="product_details_women.php?productID=' . $prod_id . '">View Product Details</a></td></tr>';
}
$dynamicList .= '</table>';
echo $dynamicList;
答案 1 :(得分:0)
$columncount = 0;
$dynamicList = '<table width="744" border="0" cellpadding="6"><tr>';
while( $row3 = sqlsrv_fetch_array( $stmt3))
{
$prod_name = $row3['product_name'];
$prod_price = $row3['product_price'];
$prod_desc = $row3['description'];
$dynamicList .= '<td width="135"><a href="product_details_women.php?productID=' . $prod_id . '">
<img src="images/products/Small/Women/' . $prod_id . '.jpg" alt="' . $prod_name . '" width="129" height="169" border="0">
</a>
</td>
<td width="593" valign="top">' . $prod_name . '<br>
£' . $prod_price . '<br>
<a href="product_details_women.php?productID=' . $prod_id . '">View Product Details</a></td>';
if($columncount == 2)
{
$dynamicList .= '</tr><tr>';
$columncount = 0;
}
else
{
$columncount++;
}
}
$dynamicList .= '</tr></table>';
echo $dynamicList;