how to use the loop and array with php

advertisements

I am newbie in programming php, i have output query data from database like this

name    activity  payment
english  activ A   20
english  activ B   25
english  activ c   30
biology  activ d   50
biology  activ e   60

but i want to show output like this:

name    activity  payment
english  activ A   20
         activ B   25
         activ c   30
biology  activ d   50
         activ e   60

how logic program use PHP to show only one name in the same name?

can you solve this problem?


database will show names same as

name    activity  payment
english  activ A   20
english  activ B   25
english  activ c   30
biology  activ d   50
biology  activ e   60

but if you want to show records as

name    activity  payment
english  activ A   20
         activ B   25
         activ c   30
biology  activ d   50
         activ e   60

you can do this in php

for example

$datas = $fetched_data; // $fetched_data store all data which is selected          from database
// now in php use foreach loop
$previous_colm = "";
foreach($datas as $data){
    if($previous_colm == $data['name']){
          // echo without printing column name again
          echo $data['activity']." ".$data['payment'];
    }else{
         // echo with new column name
         echo echo $data['name']." ".$data['activity']." ".$data['payment'];
    }
    $previous_colm = $data['name'];
}

now this will output same as you want...!!!