2012-03-24 14 views
0

MSSQL Query Link ist dies; click here for pictureMehrdimensionale Arrays zwei Schleifen

und meine Ausgabe zeigt drei verschiedene Bilder für das gleiche Produkt wie unten gezeigt. Was ich will ist, wenn das Produkt das gleiche ist, behalten Sie nur ein Bild und dann die Farben und Größen für dieses Produkt.

Mittel;

Mein Ausgang Das folgende Bild zeigt,

click here for picture

, wie Sie es sehen drei Produkt im Bild sind, aber sie sind das gleiche Produkt mit verschiedenen Farben und Größen, anstatt jedes Mal das gleiche Produkt zu sehen Ich möchte meine Ausgabe wie auf dem Bild unten.

 
<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> 
 

+0

Ich weiß nicht, Englisch Ihre Muttersprache ist. Das ist in Ordnung, aber deine Frage ist immer noch schwer zu verstehen. Vielleicht könnten Sie versuchen, ein bisschen mehr zu klären? – rdlowrey

+0

Erweiterung auf Rdlowrey Kommentar, können Sie uns die MySQL-Abfrage zeigen, um die Daten zu holen und ein Beispiel dafür, wie die Ausgabe aussehen soll? – sdjuan

+0

danke, aber wie soll die Ausgabe aussehen. Was soll es zeigen? Ich frage, damit ich sehen kann, was Sie von den Schleifen wollen. – sdjuan

Antwort

0

Ich denke, das ist das, was Sie suchen, 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 } }?> 
+0

vielen Dank für Ihre Hilfe werde ich morgen versuchen schätzen – Hanifeoglu

+0

[das ist genau das, was ich brauche] (http://jsfiddle.net/sv8ZS/) – Hanifeoglu

+0

@salihhanifeoglu: Haben Sie die Änderungen implementiert, die ich vorgeschlagen habe? Hat es funktioniert? – codef0rmer

0
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>"; 
?> 
Verwandte Themen