我有一点问题。我有一个导航栏
| home | view | view(active) | view(deleted) |
当我点击查看时,我会被带到view.php
仅检索所有数据库记录的位置:
SELECT * FROM inventory
在我的库存表中,我有一个名为的列status
,其值为y
or n
。(y
对于活动,n
对于不活动(或已删除))。
当我单击view(active)
和view(deleted)
链接时,我想执行不同的查询,例如:
SELECT * FROM inventory WHERE status LIKE 'y' (for retrieval of active records)
SELECT * FROM inventory WHERE status LIKE 'n' (for retrieval of deleted records)
如果我附加?view=y
到我的view.ph
p 链接的末尾,它工作正常。我的表单的表单操作引用自身(view.php
),除了附加的视图类型:?view=y
或者?view=n
然后有条件确定要执行的 mysql 查询。但是,我想用 POST 处理这种情况,但它不起作用。我不希望我的 URL 中有任何值。$_GET
虽然工作得很好。
谢谢。
CODE(用于查询的 view.php 条件)
if ($_POST['view'] == "y") {
$result = mysql_query("SELECT * FROM inventory WHERE status LIKE 'y'"); }
else if ($_POST['view'] == "n") {
$result = mysql_query("SELECT * FROM inventory WHERE status LIKE 'n'"); }
else if ($_POST['submit'] == "search") {
$result = mysql_query("SELECT * FROM inventory WHERE descrip LIKE '%$searchString%'"); }
else {
$result = mysql_query("SELECT * FROM inventory"); }
CODE(我的导航栏)
<div id="navigation">
<a href="add.php"><input type="button" value="ADD" /></a>
<a href="view.php"><input type="button" value="VIEW" /></a>
<a href="view.php?view=y"><input type="button" value="view active" /></a>
<a href="view.php?view=n"><input type="button" value="view deleted" /></a>
<div><br />
<form action="view.php" method="POST">
<input type="text" name="searchDescription" id="search" placeholder="search for text in description" value="<?php echo $_POST['searchDescription']; ?>"/>
<input type="submit" value="SEARCH" name="submit" id="searchDescriptionButton" />
</form>
</div>
</div>