Retrieve value chekbox from DB table join

hello,

i would like retrieve value chekbox from DB table join.

for an Update page,

my SELECT table ‘pages’

$q = "SELECT p.user_id,p.status, p.title, p.cat_p_id, GROUP_CONCAT(t.tag) AS tag , p.summary, p.ingredient, p.recipe, p.tips, p.filename
			FROM pages AS p
			LEFT JOIN pages_tag AS pt USING (page_id)
			LEFT JOIN tag AS t USING(tag_id)
			WHERE p.page_id=?";

for $tag , the result is for example:

$tag=(végétarien,classique);

I must transform this result as
$tag(végétarien,1);
$tag(classique, 5);

because in my table ‘Tag’ = (tag,tag_id).
“végetarien” => ‘1’ ,“végétalien” => ‘2’, “sans gluten” =>‘3’,“sans lactose”=> ‘4’,“classique” => ‘5’

How can I do to assign property values ​​to the right checkbox ?

Thanks

best regards

the html form for checkbox


<div class="checkbox form-control">
		<label for="tag" class="control-label">Tag</label>
		<?php
		$qt="SELECT tag, tag_id FROM tag ORDER BY tag DESC";
		$r=mysqli_query($dbc,$qt);
			while ($rowt=mysqli_fetch_array($r, MYSQLI_ASSOC)) {	?>

			<div class="checkbox <?php if(array_key_exists('tag', $update_page_errors)) echo ' has-error'; ?>">
					 	<label>
						 	<input type="checkbox" name="tag[]" id="<?php echo $rowt['tag'] ?>" value="<?php echo $rowt['tag_id'] ?>"
						 	<?php if( isset($tag) && ($tag_id == $rowt['tag_id']) ) echo !empty('checked="checked"')?'checked="checked"':'';?>><?php echo $rowt['tag'] ?>
					 	</label>
				</div>
				
				
		    <?php if(array_key_exists('tag', $update_page_errors)) echo'<span class="help-bloc">'.$update_page_errors['tag'].'</span>'; ?>
		
			<?php } ?>
	</div>	

hello,
for more information

What is the problem ?
‘Tag’ is a link table to table ‘Pages’ by a link table’ Pages_tag.
$ tag is from the comic by a join, this is the ‘name’ tag that I found. One example is ‘vegan’.
$ tag_id is the index according to its position dan table ‘Tag’ composed of tag, tag_id
So according to my table if I vegan, its tag_id is 2

this is the way to match and thus validate that returns me the SELECT query
I am trying to do so that my form checkbox is checked well.

my table with Tag matches
Tag Array ([tag] => vegetarian [tag_id] => 1) vegetarian
Array ([tag] => vegetarian [tag_id] => 2) Vegan
Array ([tag] => lactose [tag_id] => 4) without lactose
Array ([tag] => gluten-free [tag_id] => 3) gluten-free
Array ([tag] => Classic [tag_id] => 5) Classic

thank you in advance for an idea
best regards

Hello,

sorry but i find the soluce.

when you would retrieve and compare an array use function

in_array();

So in my checkbox i do that and that match

<div class="checkbox form-control">
		<label for="tag" class="control-label">Tag</label>
		<?php 
		$qt="SELECT tag_id, tag FROM tag ORDER BY tag DESC";
		$r=mysqli_query($dbc,$qt);
			while ($rowt=mysqli_fetch_array($r, MYSQLI_ASSOC)) {
			
			//print_r($rowt);
			
			$monTag_id = $rowt['tag_id'];
			$monTag = $rowt['tag'];
			
			?>
			<div class="checkbox <?php if(array_key_exists('tag', $update_page_errors)) echo ' has-error'; ?>">
					 	<label>
						 	<input type="checkbox" name="tag[]" id="<?php echo $monTag ?>" value="<?php echo $rowt['tag_id'] ?>"
						 	<?php 
						 	//print_r($tagNom);
						 	if( isset($tagNom) && in_array( $monTag , $tagNom ) ) echo !empty('checked="checked"') ? 'checked="checked"' : '';?>><?php echo $rowt['tag'] ?>
					 	</label>
				</div>
				
				
		    <?php if(array_key_exists('tag', $update_page_errors)) echo'<span class="help-bloc">'.$update_page_errors['tag'].'</span>'; ?>
		    
			<?php } ?>
	</div>	   

thanks and best regards