Select checkboxes from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kilbey1
Forum Newbie
Posts: 4
Joined: Tue Nov 26, 2002 7:18 pm
Location: Pittsburgh

Select checkboxes from database

Post by kilbey1 »

Can someone get me started on this?

I've got code set up display a main category of checkboxes, and their children, using SQL and pulling that info from a database.

It looks like this:

Code: Select all

<?php
//start code here to POPULATE main categories

$sql="SELECT parent_id, cuisine_id,cuisine_name
FROM dining_cuisine
WHERE parent_id is null
ORDER BY cuisine_name";
$result=$db->query($sql);
echo mysql_error();

while($row_cuisine=$result->fetchrow(2)){

	$cuisine_html.="<input type="checkbox" name="cuisine[]" value="$n"";

//start code here to select MAIN categories

//		$sql2="SELECT dining_cuisine_link.cuisine_link_id, dining_cuisine_link.cuisine_id, dining_cuisine_link.restaurant_id,
//		dining_restaurants.restaurant_id
//		FROM dining_cuisine_link, dining_restaurants
//		WHERE dining_restaurants.restaurant_id=dining_cuisine_link.restaurant_id";
//		$result_sub1=$db->query($sql2);

//		while($row_cuisine[cuisine_link_id]){	
//			$cuisine_html.=" checked";	
//		}

		

	$cuisine_html.=">$row_cuisine[cuisine_name]<BR>";

//start code here to POPULATE sub-categories

	$sql="SELECT parent_id, cuisine_id, cuisine_name 
	FROM dining_cuisine 
	WHERE parent_id=$row_cuisine[cuisine_id] 
	ORDER BY cuisine_name";
	$result2=$db->query($sql);
	echo mysql_error();

	while($row_cuisine_sub=$result2->fetchrow(2)){
		$cuisine_html.="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="cuisine[]" value="$n"";

//start code here to select sub-categories

//			if($row_cuisine_sub[$cuisine]){	
//			$cuisine_html.=" checked";	
//			}

	$cuisine_html.=">$row_cuisine_sub[cuisine_name]<BR>";

	}


}

?>
Notice the COMMENT tags. I thought this was approximately where I need to write my SQL and while statements to check the checkboxes, but it's just not working!!!

I could use some rearranging of the code to get a better idea of how and where I need to put code to select the checkboxes from the database.
Post Reply