0

我正在尝试在动态生成的表中显示从数据库获取的图像,该表将像这样连续显示 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循环中,但这也不起作用

4

2 回答 2

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;
于 2012-05-13T11:18:37.760 回答
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;
于 2012-05-13T11:20:21.187 回答