Notice: Undefined variable: where
Notice: Undefined variable: search
我在所有页面上都收到了这两条通知。
我该如何解决这些问题?
刚刚添加了输入类型。
<input type="text" name="search" value="<?= $search; ?>" />
<input type="submit" name="submit" value="search" />
<?php
if (!isset($page)) {
$page = 1;
}
$view = 50;
$start = ($view * $page) - $view;
//
if (isset($search)) {
$where = "WHERE `first` LIKE '%$search%' OR `second` LIKE '%$search%'";
}
$i = 0;
$query = mysql_query("SELECT `first`, `second` FROM `table_one` $where ORDER BY `id` ASC LIMIT $start, $view");
while ($row = mysql_fetch_object($query)) {
?>
答案 0 :(得分:1)
if (isset($search)) {
$where = "WHERE `first` LIKE '%$search%' OR `second` LIKE '%$search%'";
}
此部分需要else语句或$where
需要具有默认值。如果未设置$search
,则永远不会设置$where
。
$where = "";
if (isset($search)) {
$where = "WHERE `first` LIKE '%$search%' OR `second` LIKE '%$search%'";
}