473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. <table width="1000" align="center">
  2.   <tr>
  3.     <td>Item amount</td>
  4.     <td>Item name</td>
  5.   </tr>
  6.   <?
  7.         $query="SELECT * FROM item WHERE orderr_reference ='$ref'";
  8.         $result=mysql_query($query);
  9.  
  10.         $num=mysql_numrows($result);
  11.  
  12.  
  13.         $i=0;
  14.         while ($i < $num) {
  15.  
  16.         $item_amount = mysql_result($result,$i,"item_amount");
  17.         $item_name = mysql_result($result,$i,"item_name");
  18.   ?>
  19.   <tr>
  20.     <td><?=$item_amount;?></td>
  21.     <td><?=$item_name;?></td>
  22.  
  23.   </tr>
  24.   <?
  25.   $i++;
  26.   }
  27.   ?>
  28. </table>
  29.  
  30.  
  31.  
Feb 12 '10 #1
1 1585
Atli
5,058 Expert 4TB
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_array, and it's siblings, are much faster, in general.

And short_tags are bad! :-]
(See PHP manual: Escaping from HTML.)
Feb 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

59
by: AK | last post by:
I tried to google "skip scan DB2" but came up with nothing. Does DB2 have the feature under a different name?
2
by: Patrik | last post by:
Hi, I cannot find the right way to write this code. I keep getting the error : Next without For Here's my code. For Each Choix In RapInd_Code.ItemsSelected S6 =...
24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
2
by: James | last post by:
How would I skip an item in a foreach loop without breaking out of the loop altogether? foreach(SearchResult resCol1 in resCol) { string myString = resCol1.Properties.ToString(); if...
3
by: AdamM | last post by:
How can I skip an element in a foreach loop? Break seems to jump completely out of the foreach. I just want to move along to the next element based on some condition. Thanks in advance! Adam
5
by: rod.weir | last post by:
Hello, I have the following code to iterate through each view in a SQL Server and call the "sp_refreshview" command against it. It works great until it finds a view that is damaged, or otherwise...
2
by: magix | last post by:
I have an drop down list let say: <SELECT name="id" id="id" OnClick="Skip()"> <option value="0"></option> <option value="1">Item 1</option> <option value="2">Item 2</option> <option...
2
by: nano | last post by:
Does sql server have a way to handle errors in a sproc which would allow one to insert rows, ignoring rows which would create a duplicate key violation? I know if one loops one can handle the error...
18
by: luckyyyyyy | last post by:
I appriate your work but... guys i have another problm.....i wana skip first 9 lines from my data file and after skipping i wana read x,y,z at the end of file. i did but after while loop is end it...
32
by: ndedhia1 | last post by:
Right now, I am using this line of code to get rid of data in a file called alarmNotification that I do not want: egrep "low debug.*\".*\"" $dbDir/alarmNotification.log but I am having some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.