Jump to content


Photo

Query Problem.....with Condition


  • Please log in to reply
4 replies to this topic

#1 jjdave

jjdave
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2006 - 07:49 PM

Hi All,
I am reading  Data into Array (id, part_no, part_desc, part_region etc.)
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
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.

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 13 September 2006 - 08:10 PM

Firstly, sort the array on ID. Then print like:
$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'];
   }
}

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 jjdave

jjdave
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2006 - 08:25 PM

Thank you so much, I am trying out the code. Thanks again.

#4 jjdave

jjdave
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2006 - 08:33 PM

Once Again, Thank You. It worked out great. Been at it for 3 Days, on and off...

#5 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 13 September 2006 - 08:36 PM

You're welcome.

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users