GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, February 20, 2011

Drupal Database Access

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [name] => lady gaga
            [age] => 25
            [city] => new york
        )

    [1] => stdClass Object
        (
            [id] => 2
            [name] => luna maya
            [age] => 27
            [city] => denpasar
        )

)
The above is the result of this function
function get_data(){
 $output = '';
 $select = db_select('data_siswa','c')->fields('c')->execute()->fetchAll(); 
 return print_r($select); 
}
 
To get the data as a table, use this one:
function introo(){
 $output = '<table>';
 $output .= '<tr><th>Name</th><th>Age</th><th>City</th></tr>';
 
 $select = db_select('data_siswa','c')->fields('c')
                                    ->execute()->fetchAll();
      foreach($select as $key){
  $output .= '<tr><td>'.$key->name ."</td><td>";
                $output .=  $key->age. "</td><td>". $key->city ."</td></tr>";
 }
 
 $output .= "</table>";
 
 return $output; 
} 

Share/Bookmark

No comments:

Post a Comment