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
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>';
?>

Link to comment
Share on other sites

Ive tried that and it gives me this error

'Warning: mysql_fetch_object() expects parameter 1 to be resource, boolean given in starters.php on line 19'

 

Heres the db table names.

Table Name : starters

Column names : id, starter, extra

 

Cheers

Chris

 

 

 

Link to comment
Share on other sites

<?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>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.