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;

                        }

                        }
                        ?>

しかし、何らかの理由で、画像はずっと下の 1 つの列にしか表示されません。行ごとに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 に答える