<?php
$age1 = isset($_GET['age1']) ? $_GET['age1'] : "";
if ($age1 <= "18")
{
$sql = 'select * from events where type_id='.$id.' and id = "1"';
$tid = mysqli_query($conid, $sql);
}
else
{
$sql = 'select * from events where type_id='.$id.'';
$tid = mysqli_query($conid, $sql);
}
?>
-----------
<tr>
<td class="style1">Age:</td>
<td class="style2"><input type="text" name="age1" id="age1" class="form-control22" autocomplete="off"></td>
</tr>
<tr>
<td class="style1">Event Type:</td>
<td class="style2"><select name="event_id" class="ddl" id="event_id" onchange="geteventprice()">
<option value="0">--Select Event Type--</option>
<?php while($evt= mysqli_fetch_object($tid))
{
echo '<option value="'.$evt->id.'">'.$evt->name.'</option>'; } ?>
</select>
</td>
</tr>
其他声明无效......
答案 0 :(得分:0)
算术运算对字符串值不起作用。更新您的代码,如:
if ($age1 <= 18)
{
$sql = 'select * from events where type_id='.$id.' and id = "1"';
$tid = mysqli_query($conid, $sql);
}
else
{
$sql = 'select * from events where type_id='.$id.'';
$tid = mysqli_query($conid, $sql);
}
答案 1 :(得分:0)
<?php
$sql = 'select * from events where type_id='.$id.'';
if (isset($_GET['age1']) <= 18)
{
$sql.= 'and id = 1';
}
$tid = mysqli_query($conid, $sql) or die(mysqli_error($conid));
?>
如何使用这种方式。它更干净,更容易理解。您还可以查看查询是否存在问题