lional Posted March 31, 2013 Share Posted March 31, 2013 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/276339-join-two-mysql-tables-with-php/ Share on other sites More sharing options...
Barand Posted March 31, 2013 Share Posted March 31, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/276339-join-two-mysql-tables-with-php/#findComment-1422060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.