$query = db_select('mytable', 'n')
->fields('n')
->execute();
$rows = array();
while($data = $query->fetchAssoc()){
// Fill the table rows
$data['operation'] = l(t('Delete'), 'admin/mid-modules/component/' . $data['cid'] . '/delete');
$data['operation'] .= "|";
$data['operation'] .= l(t('Edit'), 'admin/mid-modules/component/' . $data['cid'] . '/edit');
$rows[] = array('data' => $data, 'style' => 'word-break:break-all;',);
}
// Prepare table header
$header = array( t('S.No'),t('Component Name'));
// Output of table with the paging
$output = theme_table(
array(
"header" => $header,
"rows" => $rows,
"attributes" => array(),
"sticky" => true, // Table header will be sticky
"caption" => "",
"colgroups" => array(),
"empty" => t("Table has no row!") // The message to be displayed if table is empty
)
);
return $output;
//following menus that delete or edit your selected content
$items['admin/mid-modules/component/%ctools_js'] = array(
'page callback' => 'popup_callback',
'page arguments' => array(3),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'file' => 'popup.inc'
);
$items['admin/mid-modules/component/%/delete'] = array(
'title' => 'Delete Component item',
'page callback' => 'delete_me',
'page arguments' => array('delete_component_record_comfirm',3),
'access arguments' => array('administer users'),
'type' => MENU_CALLBACK,
'file'=>'delete_record.inc',
);
/**
* Delete Record Confirmation ------------------------------------
*/
function delete_component_record_comfirm($form, &$form_state, $cid){
// print_r($cid);exit;
$form['delete'] = array(
'#type' => 'value',
'#value' => $cid,
);
return confirm_form(
$form,
t('Are you sure you want to delete this?'),
'admin/mid-modules/component/'. $data['cid'],
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* Delete Survey Record Function
*/
function delete_component_record_comfirm_submit($form, &$form_state) {
$record = $form_state['values']['delete'];
if ($record ) {
$num_deleted = db_delete('mid_components')
->condition('cid', $record )
->execute();
drupal_set_message('The record has been deleted!');
}
$form_state['redirect'] = "admin/mid-modules/component";
}