Jump to content

Checkboxes and Mysql


skoobi

Recommended Posts

Hi im struggling to find a way to list a few items and have a checkbox next to them to select it...

 

Basicly i have a web form for orders which it willl display a list of the specials from a database and it will be in list format and you then choose which items in that list...

 

example:

Soup of the day  || (Checkbox)

Prawn Salad  || (Checkbox)

 

The difficult part which i cannot get my head around is populating the list with the data from the database...

 

Any help would be greatful...

 

Cheers

Chris

Link to comment
https://forums.phpfreaks.com/topic/192627-checkboxes-and-mysql/
Share on other sites

Why can't you just place a check box next to it?

 

<?php
$sql = mysql_query("SELECT * FROM menu");

echo '<table>';
while ($item = mysql_fetch_object($sql)) {
  echo '<td>'. $item->name .'</td>';
  echo '<td><input type="checkbox" name="selected[\''. $item->name .'\']" />';
}
echo '</table>';
?>

<?php
$sql = mysql_query("SELECT * FROM starters");

echo '<table>';
while ($item = mysql_fetch_object($sql)) {
  echo '<td>'. $item->starter .'</td>';
  echo '<td><input type="checkbox" name="selected[\''. $item->starter .'\']" />';
}
echo '</table>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.