umershaikh Posted March 14, 2011 Share Posted March 14, 2011 Hi i have three tables in wordpress databass wp_term_taxonomy, wp_terms, wp_usercat, i have created a profile custom fields, i have a jobsite there is lot of check boxes for which job user want. data in these three tables i have inserted records in these tables but how can i puplate records which checkboxes with checked in user profile edit page. The code is this i have used but this not working form me Please Help me. <?php $userid = $_GET['user_id']; $catresult = mysql_query ("select DISTINCT * from wp_terms a, wp_term_taxonomy b where b.parent = a.term_id GROUP BY a.term_id"); while ($row = mysql_fetch_array ($catresult)) { $cat_id = $row['parent']; $cat_name = $row['name']; echo '<h2>'.$cat_name.'</h2>'; $subcatresult = mysql_query("select * from wp_terms a, wp_term_taxonomy b where b.term_id = a.term_id and b.parent = $cat_id"); while ($row1 = mysql_fetch_array ($subcatresult)) { $usercats = mysql_query("SELECT * FROM wp_usercat"); $scat_name = $row1['name']; $scat_id = $row1['term_id']; if ($scat_id = $user_id) { echo '<input style="margin:9px;" "type="checkbox" name="category[]" value="'.$scat_id.'" checked="checked"/>'.$scat_name.''; } else{ echo '<input style="margin:9px;" "type="checkbox" name="category[]" value="'.$scat_id.'/>'.$scat_name.''; } } } ?> Quote Link to comment Share on other sites More sharing options...
Ionisis Posted March 30, 2011 Share Posted March 30, 2011 For starters, stop appending strings, and use commas. It will make your scripts faster and consume less memory. When using echo, watch how i do; By the way, your quotes are not nested correctly: Yours: echo '<input style="margin:9px;" "type="checkbox" name="category[]" value="'.$scat_id.'/>'.$scat_name.''; Mine : echo '<input style="margin:9px;" type="checkbox" name="category[]" value="',$scat_id,'"/>',$scat_name; if ($my_relevant_val == 'some_value'){ echo '<input style="margin:9px;" type="checkbox" name="category[]" value="',$scat_id,'" checked="checked"/>',$scat_name; }else{ echo '<input style="margin:9px;" type="checkbox" name="category[]" value="',$scat_id,'"/>',$scat_name; } Quote Link to comment 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.