displaying distinct rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cbitongg
    New Member
    • Jan 2007
    • 3

    displaying distinct rows

    Hello,

    How do you display distinct fields when a query returns an array ??

    This is the current output of my query:

    PF0001 WB1 D1-drd-N1
    PF0001 WB1 D1-drd-N2
    PF0001 WB1 D1-drd-N3

    and I want it to display like this:

    PF0001 WB1 D1-drd-N1
    D1-drd-N2
    D1-drd-N3
    this is the result of 1 query..so i display it using mysql_fetch_arr ay
    but i dont know how to display it the way i want it..the redundant first two fields should display only once.
    Anybody who could help me??
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I don't know your output layout, but something like the following[php]// Assuming $row['field1'] and $row['field2'] contain header info
    // and $row['field3'] the detail info
    $save_fields="" ;
    while ($row=mysql_fet ch_array(your_o bject)) {
    $hdr_fields = $row['field1'].$row['field2'];
    if ($hdr_fields != $save_fields) {
    $save_fields = $hdr_fields;
    echo $row['field1']." ".$row['field2'];
    }
    echo $row['field3'];
    }[/php]
    Ronald :cool:

    Comment

    • ctsasikumar
      New Member
      • Nov 2006
      • 17

      #3
      [php]

      //query execution
      $count=mysql_nu m_rows($query);
      for($i=0;$i<$co unt;$i++)
      {
      $get_resutl=mys ql_fetch_array( $query)

      $filed1=$get_re sutl['filed_name1'];
      $filed2=$get_re sutl['filed_name2'];
      $filed3=$get_re sutl['filed_name3'];

      if($i==0)
      {
      echo $filed1;
      }

      echo $filed2;
      echo $filed3
      echo "<br>";
      }
      [/php]

      Comment

      Working...