HEY GUYS我从复选框中删除了一个数据,这是代码:
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
}
?>
使用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')";
这很有效。我做了结果....所以输入需要是例如:
flower type Occasions Categories
12 Red Roses Birthday;Anniversary;Valentines Bouqets
1 Red Rose Birthday;Valentines Bouqets;Flowerarrangment
现在我需要做一个下拉列表。如果用户选择周年纪念日,则仅显示12个红玫瑰,但如果用户选择生日,则需要显示两个花。
我尝试了这段代码,但它无法正常工作。他只向我展示了有一种类型场合的花,例如24朵玫瑰只有生日场合,用户选择生日。
这是我试过的代码:
$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>';
}
我在下拉列表中显示它。
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
}
}
?>
如果有人可以帮助我,我真的很感激,谢谢你。