HEY GUYS I implode a data from checkboxes this is the code:
To Show Checkboxes from Different tables:
<?php
$query23 = "SELECT * from tbl_occasions";
$result23 = mysqli_query($conn, $query23)
or die("Error in query: ". mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result23))
{
?>
<div class="col-md-12">
<label class="checkbox" for="checkboxes">
<input type="checkbox" name="reg_occassions[]" value="<?php echo $row['name'];?>"><?php echo $row['name']?>
</label>
</div>
<?php
}
?>
<?php
$query24 = "SELECT * from tbl_categories";
$result24 = mysqli_query($conn, $query24)
or die("Error in query: ". mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result24))
{
?>
<div class="col-md-12">
<label class="checkbox" for="checkboxes">
<input type="checkbox" name="reg_categories[]" value="<?php echo $row['name'];?>"><?php echo $row['name']?>
</label>
</div>
<?php
}
?>
To insert into database with implode:
$occasions = implode( ';' , $_POST['reg_occassions'] );
$categories= implode( ';' , $_POST['reg_categories'] );
$query = "INSERT INTO tbl_flower (flower_type, website_description,florist_description,name,image,enabled,florist_choice,categories,occasions)
VALUES ('$flowertype', '$websitedescription', '$floristdescription','$name', '$upfile', '$enabled','$floristchoice', '$categories','$occasions')";
This is working. i made the result.... so the input need to be for example :
flower type Occasions Categories
12 Red Roses Birthday;Anniversary;Valentines Bouqets
1 Red Rose Birthday;Valentines Bouqets;Flowerarrangment
Now i need to do a dropdownlist of occasions. If the user choose Anniversary only 12 Red Roses will appear but if the user choose Birthday , both flowers need to appear.
I tried this code but it's not working right. He is showing me only flower that are with 1 type of occasions for example 24 Roses has Birthday occasion only and the user choose Birthday.
This is the code i tried:
$query = "SELECT * FROM tbl_occasions";
$result= mysqli_query($conn, $query)
or die("Error in query: ". mysqli_error($conn));
$option ="";
while ($row = mysqli_fetch_assoc($result)){
$option .= '<option name = "'.$row['name'].'" value = "'.$row['name'].'">'.$row['name'].'</option>';
}
And i show it in a dropdown list.
if(isset($_POST['submit'])){
$_SESSION['selected'] = $_POST['reg_occasion'];
$query2 = "SELECT occasions from tbl_flower";
$result2= mysqli_query($conn, $query2)
or die("Error in query: ". mysqli_error($conn));
while ($row = mysqli_fetch_array($result2)){
$data = $row["occasions"];
$da = explode(";" , $data);
}
$query1= "SELECT * FROM tbl_flower WHERE occasions NOT LIKE '". $da ."'";
$result1= mysqli_query($conn, $query1)
or die("Error in query: ". mysqli_error($conn));
$result1_rows = mysqli_num_rows($result1);
while ($row = mysqli_fetch_array($result1)){
?>
<tr>
<td><?php echo $row['name']?></td>
<td><?php echo $row['position']?></td>
<td> <a href="editoccasionposition.php?id= <?php
echo $row['id']?>"><input type="button" class="btn btn-secondary" name="edit " value="Edit Position"></a></td>
</tr>
<?php
}
}
?>
If someone can help me i really appreciate, Thank you.