简体   繁体   English

多维数组两个循环

[英]Multidimensional Arrays two loops

MSSQL query link is this; MSSQL查询链接是这个; click here for picture 点击这里查看图片

and my output shows three different pictures for the same product as shown below. 我的输出显示相同产品的三张不同图片,如下所示。 What I want is, if the product is the same, keep just one picture and then get the colors and sizes for that product. 我想要的是,如果产品相同,则只保留一张图片,然后获取该产品的颜色和尺寸。

Means; 手段;

My output ıs the picture below, 我的输出是下面的图片,

click here for picture 点击这里查看图片

as you see there are three product in the picture but they are the same product with different colors and sizes, instead of seeing the same product every time, I want my output like in the picture below. 如您所见,图中有三种产品,但是它们是具有不同颜色和尺寸的同一产品,而不是每次都看到同一产品,我希望我的输出如下图所示。

 
<table width="376" cellspacing="0"  class="stats" width:100%> 
<tr> 
<td colspan="9" align="center"><?php echo $secim ?></td> 
</tr> 
<?php 
while(odbc_fetch_into($sql_result, &$row)) { 
$unit1 = floor($row[3]); 
$unit2 = floor($row[4]); 
$unit3 = floor($row[5]); 
$unit4 = floor($row[6]); 
$unit5 = floor($row[7]); 
?> 
<tr> 
  <td colspan="2" align="left" valign="top"><?php echo"$row[0]";?></td> 
  <td>36</td> 
  <td>38</td> 
  <td>40</td> 
  <td>42</td> 
  <td>44</td> 
</tr> 
<tr>       
<td width="114" align="right" valign="top">
<img src= <?php echo"images/Resize/$row[2]"?>></td> 
 <td width="25" valign="top"><?php echo"$row[1]";?></td> 
 <td width="25"valign="top"><?php echo"$unit1";?></td> 
 <td width="25"valign="top"><?php echo"$unit2";?></td> 
 <td width="25"valign="top"><?php echo"$unit3";?></td> 
 <td width="25"valign="top"><?php echo"$unit4";?></td> 
 <td width="25"valign="top"><?php echo"$unit5";?></td> 
 </tr> 
 <?php }  }?> 
 <?php  
 odbc_free_result($sql_result); 
 odbc_close($connection); 
 ?> 
 </table>

                    
                       
                    

I think this is what you are looking for, http://jsfiddle.net/sv8ZS/ 我认为这就是您要寻找的东西, http://jsfiddle.net/sv8ZS/

while(odbc_fetch_into($sql_result, &$row)) { 
$unit1 = floor($row[3]); 
$unit2 = floor($row[4]); 
$unit3 = floor($row[5]); 
$unit4 = floor($row[6]); 
$unit5 = floor($row[7]); 
?> 
//you can check with the index to see if its a first row or not
//This will avoid printing the same header for each row.
if (this-is-the-first row) {
  <tr> 
    <td colspan="2" align="left" valign="top"><?php echo"$row[0]";?></td> 
    <td>36</td> 
    <td>38</td> 
    <td>40</td> 
    <td>42</td> 
    <td>44</td> 
  </tr> 
} 
//above if ends
<tr>  
//If its not a first row then do not show the image again and merge all the next rows
if (this-is-the-first-row) {     
   <td width="114" align="right" valign="top" rowspan='3'>
    <img src= <?php echo"images/Resize/$row[2]"?>
   </td>  
 }
 //above if ends 
 <td width="25" valign="top"><?php echo"$row[1]";?></td> 
 <td width="25"valign="top"><?php echo"$unit1";?></td> 
 <td width="25"valign="top"><?php echo"$unit2";?></td> 
 <td width="25"valign="top"><?php echo"$unit3";?></td> 
 <td width="25"valign="top"><?php echo"$unit4";?></td> 
 <td width="25"valign="top"><?php echo"$unit5";?></td> 
 </tr> 
 <?php }  }?> 
enter code here
<?php
echo "<table border='1'>
<tr>
<th>Model</th>
<th>Color</th>
<th>Unit</th>
</tr>";
?>
<?php
while($row =odbc_fetch_array($result)){
//if $row['sAciklama']=$row['sAciklama'] bla bla ???
if (this-is-the-first row) {
echo "<tr>";
echo "<td>" . $row['sAciklama'] . "</td>"; //Model First Element 
}
if (this-is-the-first-row) {  
echo "<td>" . $row['sRenkAdi'] . "</td>"; //color
echo "<td>" . $row['Kalan'] . "</td>";    //unit
echo "</tr>";
}}
echo "</table>";
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM