Heya,
I am creating a module, and am creating a function that creates a html table from one of my tables in the datasbase.
function _createtable($tablename, $return = array()){
$html_table = "";
$query = 'SELECT * FROM {'.$tablename.'}';
$count = 10;
$pager = pager_query($query, $count);
$results = db_query($query);
if (db_affected_rows() > 0 ) {
$html_table .= "<table>";
$html_table .= "<tr>";
foreach ($return as $key){
$html_table .= "<th><h5><b>". ucwords($key) ."</b></h5></th>";
}
$html_table .= "<th><h5><b>Options</b></h5></th>";
$html_table .= "</tr>";
$i = 1;
while($result = db_fetch_object($pager)){
if ($i % 2 != "0"){
$rowColor = "#ededed";
}
else {
$rowColor = "";
}
$html_table .= "<tr style=\"background-color:$rowColor;\">";
foreach ($return as $key){
$html_table .= "<td>" . $result->$key . "</td>";
}
$html_table .= "<td>" . drupal_get_form('_tablebuttons', 'SOMEVALUETOPASS') . "</td>";
$html_table .= "</tr>";
$i++;
}
$html_table .= "</table>";
}
else {
drupal_set_message (t('Currently there are no results in the database.'));
}
return $html_table . theme('pager' , $count);
}
Basically all this does is takes the field names and prints a table. What I need it to do is have and EDIT DELETE and a TICKBOX. So I created a form called htmlbuttons. As you can see every time a row is generated it creates the buttons in that row. Which is fine for edit and delete.
BUT how would I do multiple tick boxes? Because each row is an individual form. Can you capture the input from all the forms in one go if they are ticked? How would I then connect a form button to grab all that input?
Anyone have any Ideas how to do this in Drupal or any better Ideas on how to create a CRUD html table? I sort of need phpmyadmin functionality in the page but need it to be more simple and part of my module. I dont want to use other modules to create pages.
Any Ideas?
Drupal gurus?