Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP和SQL Server 2008在两列中显示动态产品列表_Php_Sql_Web_Product - Fatal编程技术网

使用PHP和SQL Server 2008在两列中显示动态产品列表

使用PHP和SQL Server 2008在两列中显示动态产品列表,php,sql,web,product,Php,Sql,Web,Product,我试图在两列(并排)中动态显示产品列表,但我不确定如何使用表 这是我在一列中显示所有产品的代码 $productCount = sqlsrv_num_rows($stmt); // count the output amount $columncount = 0; $dynamicList = '<table width="744" border="0" cellpadding="6"><tr>'; while($row = sqlsrv_fetch_array(

我试图在两列(并排)中动态显示产品列表,但我不确定如何使用表

这是我在一列中显示所有产品的代码

    $productCount = sqlsrv_num_rows($stmt); // count the output amount
$columncount = 0;
$dynamicList = '<table width="744" border="0" cellpadding="6"><tr>';
while($row = sqlsrv_fetch_array($stmt)){ 
         $id = $row["productID"];
         $product_name = $row["product_name"];
         $product_price = $row["product_price"];
         $dynamicList .= '<td width="135"><a href="product_details.php?productID=' . $id . '"><img src="images/products/Small/Men/' . $id . '.jpg" alt="' . $product_name . '" width="129" height="169" border="0"></a></td>
<td width="593" valign="top">' . $product_name . '<br>
  £' . $product_price . '<br>
  <a href="product_details.php?productID=' . $id . '">View Product Details</a></td>';

  if($columncount == 2){
    $dynamicList .= '</tr><tr>';
    $columncount = 0;
  }else
    $columncount++; 
 }

$dynamicList .= '</tr></table>';

<?php echo $dynamicList; ?><br>
$productCount=sqlsrv_num_rows($stmt);//计算输出量
$columncount=0;
$dynamicList='';
而($row=sqlsrv_fetch_数组($stmt)){
$id=$row[“productID”];
$product_name=$row[“product_name”];
$product_price=$row[“product_price”];
$dynamicList='
“.$product_name.”
“$产品价格”。
'; 如果($columncount==2){ $dynamicList.=''; $columncount=0; }否则 $columncount++; } $dynamicList.='';
如何让我的产品显示在两列而不是一列中


使用工作解决方案更新了我的帖子

您正在为结果集中的每一行创建一个表

应该是这样的:

$columncount = 0;
$dynamicList = '<table width="744" border="0" cellpadding="6"><tr>';
while($row = sqlsrv_fetch_array($stmt)){ 
         $id = $row["productID"];
         $product_name = $row["product_name"];
         $product_price = $row["product_price"];
         $dynamicList .= '<td width="135"><a href="product_details.php?productID=' . $id . '"><img src="images/products/Men/' . $id . '.jpg" alt="' . $product_name . '" width="129" height="169" border="0"></a></td>
<td width="593" valign="top">' . $product_name . '<br>
  £' . $product_price . '<br>
  <a href="product_details.php?productID=' . $id . '">View Product Details</a></td>';

  if($columncount == 3){
    $dynamicList .= '</tr><tr>';
    $columncount = 0;
  }else
    $columncount++; 
 }

$dynamicList .= '</tr></table>';

echo $dynamicList;
$columncount=0;
$dynamicList='';
而($row=sqlsrv_fetch_数组($stmt)){
$id=$row[“productID”];
$product_name=$row[“product_name”];
$product_price=$row[“product_price”];
$dynamicList='
“.$product_name.”
“$产品价格”。
'; 如果($columncount==3){ $dynamicList.=''; $columncount=0; }否则 $columncount++; } $dynamicList.=''; echo$dynamicList;
您正在为结果集中的每一行创建一个表

应该是这样的:

$columncount = 0;
$dynamicList = '<table width="744" border="0" cellpadding="6"><tr>';
while($row = sqlsrv_fetch_array($stmt)){ 
         $id = $row["productID"];
         $product_name = $row["product_name"];
         $product_price = $row["product_price"];
         $dynamicList .= '<td width="135"><a href="product_details.php?productID=' . $id . '"><img src="images/products/Men/' . $id . '.jpg" alt="' . $product_name . '" width="129" height="169" border="0"></a></td>
<td width="593" valign="top">' . $product_name . '<br>
  £' . $product_price . '<br>
  <a href="product_details.php?productID=' . $id . '">View Product Details</a></td>';

  if($columncount == 3){
    $dynamicList .= '</tr><tr>';
    $columncount = 0;
  }else
    $columncount++; 
 }

$dynamicList .= '</tr></table>';

echo $dynamicList;
$columncount=0;
$dynamicList='';
而($row=sqlsrv_fetch_数组($stmt)){
$id=$row[“productID”];
$product_name=$row[“product_name”];
$product_price=$row[“product_price”];
$dynamicList='
“.$product_name.”
“$产品价格”。
'; 如果($columncount==3){ $dynamicList.=''; $columncount=0; }否则 $columncount++; } $dynamicList.=''; echo$dynamicList;
//一个快速解决方案是存储结果行数
$nrow=行数($result);
//设置while循环的计数器
$count=0;
//在while循环中,输入if-else条件
$dynamicList='';
while($row=sqlsrv\u fetch\u数组($stmt)){
$id=$row[“productID”];
$product_name=$row[“product_name”];
$product_price=$row[“product_price”];
//在左栏中显示表格的前半部分
如果($con
//一个快速解决方案是存储结果行的数量
$nrow=行数($result);
//设置while循环的计数器
$count=0;
//在while循环中,输入if-else条件
$dynamicList='';
while($row=sqlsrv\u fetch\u数组($stmt)){
$id=$row[“productID”];
$product_name=$row[“product_name”];
$product_price=$row[“product_price”];
//在左栏中显示表格的前半部分

如果($count感谢您的快速回复。您给我的代码与我的旧代码的功能完全相同,但由于某些原因,我的产品图像无法显示。我只希望能够在左栏显示产品1,右栏显示产品2,左栏再次显示产品3,依此类推。要清楚……现在,您在第1栏显示了图像,并输入了价格第2列..您也想要第3列和第4列?这正是我想要的。我刚刚将“columncount==3”更改为“columncount==1”现在我的产品动态显示在两列中。如果我对我的问题不是很清楚,我很抱歉,我刚刚开始学习PHP。@Moyed Ansari。非常感谢。我现在唯一的问题是我的图像根本没有显示。你知道为什么它们没有显示吗?你能检查正在生成的HTML吗?我相信这与图像路径有关。感谢您的快速回复。您给我的代码与我的旧代码的功能完全相同,但由于某些原因,我的产品图像不会显示。我只希望能够在左栏显示产品1,右栏显示产品2,左栏显示产品3,依此类推。要清楚..右否你在第一栏有图像,在第二栏有价格。你也想要第三栏和第四栏?这正是我想要的。我刚把“columncount==3”改为“columncount==1”现在我的产品动态显示在两列中。如果我对我的问题不是很清楚,我很抱歉,我刚刚开始学习PHP。@Moyed Ansari。非常感谢。我现在唯一的问题是我的图像根本没有显示。你知道为什么它们没有显示吗?你能检查正在生成的HTML吗?我相信与图像路径有关的ve。