Make Check Box And Selected Option Checked in PHP
Make multiple check box and selected option checked in php according database value.
Make Selectbox checked :-
SQL Query :-
$GetCuisines = mysqli_query($obj->mysqli,"SELECT CuisineID,CuisineName,CuisinePic from contribu_yummy.cuisine where active=1 and deleted=0");
<select name="SelCuisineID" id="SelCuisineID" class="form-control" style="width:230px">
<option value="" class="Text" >Select</option>
<?php
while($cuisineRow = mysqli_fetch_array($GetCuisines))
{
if($CuisineID == $cuisineRow['CuisineID'])
{
$checkedCuisine = "selected='selected'";
}
else
{
$checkedCuisine = "";
}
?>
<option value="<?php echo $cuisineRow['CuisineID']; ?>" <?php echo $checkedCuisine; ?> ><?php echo $cuisineRow['CuisineName']; ?></option>
<?php }
?>
</select>
Make multiple checkbox checked : -
SQL Query :-
$getTags = mysqli_query($obj->mysqli,"SELECT tagID,tagName from contribu_yummy.tags where active=1 and deleted=0");
$SQL="SELECT RecipeID,RecipeName,AboutRecipe,RecipeType,OnionType,CuisineID_int,CategoryID_int,PreparationTime,CookingTime,Servings,Calories,Ingredients,Instructions,Tags,Tags
FROM `contribu_yummy`.`recipes`
WHERE RecipeID = $_REQUEST[recipeid]";
$getRecipe = mysqli_query($obj->mysqli,$SQL);
$recipeRow = mysqli_fetch_array($getRecipe);
$Tags = explode(",", $recipeRow['Tags']);
<?php
while($tagRow = mysqli_fetch_array($getTags))
{
if (in_array($tagRow['tagID'], $Tags))
{
$checkedTag = "checked='checked'";
}
else
{
$checkedTag = "";
}
?>
<div class="col-md-3">
<input type="Checkbox" id="TagID" name="TagID[]" value="<?php echo $tagRow['tagID']; ?>" <?php echo $checkedTag; ?> align="absmiddle"> <?php echo $tagRow['tagName']; ?>
</div>
<?php } ?>
Make Selectbox checked :-
SQL Query :-
$GetCuisines = mysqli_query($obj->mysqli,"SELECT CuisineID,CuisineName,CuisinePic from contribu_yummy.cuisine where active=1 and deleted=0");
<select name="SelCuisineID" id="SelCuisineID" class="form-control" style="width:230px">
<option value="" class="Text" >Select</option>
<?php
while($cuisineRow = mysqli_fetch_array($GetCuisines))
{
if($CuisineID == $cuisineRow['CuisineID'])
{
$checkedCuisine = "selected='selected'";
}
else
{
$checkedCuisine = "";
}
?>
<option value="<?php echo $cuisineRow['CuisineID']; ?>" <?php echo $checkedCuisine; ?> ><?php echo $cuisineRow['CuisineName']; ?></option>
<?php }
?>
</select>
Make multiple checkbox checked : -
SQL Query :-
$getTags = mysqli_query($obj->mysqli,"SELECT tagID,tagName from contribu_yummy.tags where active=1 and deleted=0");
$SQL="SELECT RecipeID,RecipeName,AboutRecipe,RecipeType,OnionType,CuisineID_int,CategoryID_int,PreparationTime,CookingTime,Servings,Calories,Ingredients,Instructions,Tags,Tags
FROM `contribu_yummy`.`recipes`
WHERE RecipeID = $_REQUEST[recipeid]";
$getRecipe = mysqli_query($obj->mysqli,$SQL);
$recipeRow = mysqli_fetch_array($getRecipe);
$Tags = explode(",", $recipeRow['Tags']);
<?php
while($tagRow = mysqli_fetch_array($getTags))
{
if (in_array($tagRow['tagID'], $Tags))
{
$checkedTag = "checked='checked'";
}
else
{
$checkedTag = "";
}
?>
<div class="col-md-3">
<input type="Checkbox" id="TagID" name="TagID[]" value="<?php echo $tagRow['tagID']; ?>" <?php echo $checkedTag; ?> align="absmiddle"> <?php echo $tagRow['tagName']; ?>
</div>
<?php } ?>
Comments
Post a Comment