<?php
/**
* This module show how to impelements JOIN operation.
/**
* This module show how to impelements JOIN operation.
* There's two table
* Table dmk_dosen:
* id int not null auto_increment key,
* dosen char(50)
* Table dmk_mata_kuliah:
* id int not null auto_increment key,
* mata_kuliah char(20)
*
* @type : drupal module - db, menu
* @author : irfanudin ridho
* @email : irfan.ub@gmail.com
* @version : 1.0
* @date : February 25, 2011
*/
/**
* Implements hook_menu()
*/
function dosen_matkul_menu(){
$items = array();
$items['dosen'] = array(
'title' => 'Dosen Mata Kuliah',
'page callback' => 'get_dosen_matkul',
'access callback' => TRUE,
);
return $items;
}
/**
* render the dosen and mata kuliah data to table
*/
function get_dosen_matkul(){
$output = '';
$dosen = db_select('dmk_dosen')->fields('dmk_dosen')
->execute()->fetchAll();
$matkul = db_select('dmk_mata_kuliah','mk')->fields('mk')
->execute()->fetchAll();
$output .= '<div>';
// table of dosen
$output .= '<div><h2>Daftar Dosen</h2>';
$output .= '<table><tr><th>No</th><th>Dosen</th></tr>';
$i = 1;
foreach($dosen as $key){
$output .= '<tr>';
$output .= '<td>'.$i++.'</td>';
$output .= '<td>'.$key->dosen.'</td>';
$output .= '</tr>';
}
$output .= '</table></div>';
// table of mata kuliah
$output .= '<div><h2>Daftar Mata Kuliah</h2>';
$output .= '<table><tr><th>No</th><th>Mata Kuliah</th></tr>';
$j = 1;
foreach($matkul as $key){
$output .= '<tr>';
$output .= '<td>'.$j++.'</td>';
$output .= '<td>'.$key->mata_kuliah.'</td>';
$output .= '</tr>';
}
$output .= '</table></div>';
$output .= '</div>';
return $output;
}
* Table dmk_dosen:
* id int not null auto_increment key,
* dosen char(50)
* Table dmk_mata_kuliah:
* id int not null auto_increment key,
* mata_kuliah char(20)
*
* @type : drupal module - db, menu
* @author : irfanudin ridho
* @email : irfan.ub@gmail.com
* @version : 1.0
* @date : February 25, 2011
*/
/**
* Implements hook_menu()
*/
function dosen_matkul_menu(){
$items = array();
$items['dosen'] = array(
'title' => 'Dosen Mata Kuliah',
'page callback' => 'get_dosen_matkul',
'access callback' => TRUE,
);
return $items;
}
/**
* render the dosen and mata kuliah data to table
*/
function get_dosen_matkul(){
$output = '';
$dosen = db_select('dmk_dosen')->fields('dmk_dosen')
->execute()->fetchAll();
$matkul = db_select('dmk_mata_kuliah','mk')->fields('mk')
->execute()->fetchAll();
$output .= '<div>';
// table of dosen
$output .= '<div><h2>Daftar Dosen</h2>';
$output .= '<table><tr><th>No</th><th>Dosen</th></tr>';
$i = 1;
foreach($dosen as $key){
$output .= '<tr>';
$output .= '<td>'.$i++.'</td>';
$output .= '<td>'.$key->dosen.'</td>';
$output .= '</tr>';
}
$output .= '</table></div>';
// table of mata kuliah
$output .= '<div><h2>Daftar Mata Kuliah</h2>';
$output .= '<table><tr><th>No</th><th>Mata Kuliah</th></tr>';
$j = 1;
foreach($matkul as $key){
$output .= '<tr>';
$output .= '<td>'.$j++.'</td>';
$output .= '<td>'.$key->mata_kuliah.'</td>';
$output .= '</tr>';
}
$output .= '</table></div>';
$output .= '</div>';
return $output;
}
Iki Program Opo ya?
ReplyDelete