Jump to content

I want Populate Results in Check boxes


umershaikh

Recommended Posts

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.'';
		}
	}
}

?>

Link to comment
Share on other sites

  • 3 weeks later...

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;
}

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.