Jump to content

Archived

This topic is now archived and is closed to further replies.

jjdave

Query Problem.....with Condition

Recommended Posts

Hi All,
I am reading  Data into Array (id, part_no, part_desc, part_region etc.)
[code=php:0]
Example of Data: (Not PHP Code)
ID  | Part_no  |  Part_Desc  |  Region
1  |  001    |  Valve      |  CA
2  |  121    |  Union Nut  |  WA
3  |  072    |  Fitting    |  VA
1  |  352    |  O-ring      |  AZ
[/code]
I am running while loop so it reads the Array; Now, I like to print this data with one condition; If ID 1 is printed then next time it needs to skip if the same ID is repeated.

So in example above, it should print only ID 1, 2, 3 and stop printing.

Any help will be appriciated. Thanks.

Share this post


Link to post
Share on other sites
Firstly, sort the array on ID. Then print like:
[code=php:0]
$old_id = "";
for ($i=0; $i<count($array); $i++) {
  if ($array['id'] != $old_id) {
      echo $array['id'] . ' ' . $array['part-no']... etc.;
      $old_id = $array['id'];
  }
}
[/code]

Ronald  8)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.