Skip in a loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baris22
    New Member
    • Jan 2010
    • 5

    Skip in a loop

    hello,

    this is my code. output of this code is like this:

    item amount item name

    1 jacket
    3 top
    3 top
    3 top
    1 skirt

    what can i do to show like this?
    item amount item name

    1
    jacket
    3
    top
    top
    top
    1
    skirt

    If the item amount is bigger than 1, i just want to show item amount only once and skip the other ones.

    Code:
    <table width="1000" align="center">
      <tr>
        <td>Item amount</td>
        <td>Item name</td>
      </tr>
      <?
            $query="SELECT * FROM item WHERE orderr_reference ='$ref'";
            $result=mysql_query($query);
    
            $num=mysql_numrows($result);
            
            
            $i=0;
            while ($i < $num) {
    
            $item_amount = mysql_result($result,$i,"item_amount");
            $item_name = mysql_result($result,$i,"item_name");
      ?>
      <tr>
        <td><?=$item_amount;?></td>
        <td><?=$item_name;?></td>
        
      </tr>
      <?
      $i++;
      }
      ?>
    </table>
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    How exactly does your database look like? You may be able to do this by changing the query.

    Also, you should avoid the mysql_result function. The mysql_fetch_arr ay, and it's siblings, are much faster, in general.

    And short_tags are bad! :-]
    (See PHP manual: Escaping from HTML.)

    Comment

    Working...