Jump to content

Recommended Posts

Hi

I have one table called bucket_list that lists all the available bucket lists. Another table called client_list that lists the bucket lists that the client has previously selected.

I want to create a edit facility that allows users to edit there bucket list. What I am trying to do is create a list of checkboxes that will be checked if the entry exists in the client list and show the bucket list unchecked if the user has not selected it.

 

Here is the code that I have been trying.

$query_subcat = "SELECT bucket_list.cat_id, bucket_list.category, client_list.bucket_id FROM bucket_list, client_list WHERE client_list.client_id = '$cid_out' AND bucket_list.active = '1'";
		$result_subcat = mysql_query($query_subcat, $conn);
		while ($row_subcat = mysql_fetch_assoc($result_subcat)){
		$sub_cat_id_out = $row_subcat["cat_id"];
		$subcat_out = $row_subcat["category"];
		$bucket_id_out = $row_subcat['bucket_id'];
		
print '<td width="190" align="left" valign="top"style="color:black;float:left">';
		
	
	



print '<input type="checkbox" value="' . $sub_cat_id_out . '" name="cat[' . $sub_cat_id_out . ']"'; 
if ($bucket_id_out == $sub_cat_id_out) {
print 'checked="checked">';
} 
print '  ' . $subcat_out . '</td>';

 

Link to comment
https://forums.phpfreaks.com/topic/276339-join-two-mysql-tables-with-php/
Share on other sites

If I understand your table structure

 

SELECT bucket_list.cat_id, bucket_list.category, client_list.bucket_id 
FROM bucket_list
LEFT JOIN client_list 
    ON client_list.client_id = '$cid_out' 
    AND client_list.bucket_id = bucket_list.cat_id
WHERE  bucket_list.active = '1'

 

client_list.bucket_id will be NULL if not selected

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.