的index.php
textarea值传递给另一个页面,但它只执行一个查询
搜索页面
<?php
$text = trim($_POST['textarea']);
$textAr = explode("\n", $text);
$textAr = array_filter($textAr, 'trim'); // remove any extra \r characters left behind
foreach ($textAr as $line) {
}
$count=count($textAr);
for($i=0;$i<$count;$i++)
{
$cusdet = "SELECT * from `product` WHERE category LIKE '%" .$textAr[$i]. "%'";
echo "SELECT * from products where name='$textAr[$i]'<br><br>"; ?>
<?php
$query = mysql_query($cusdet) or die(mysql_error()) ;
while ($row = mysql_fetch_array($query)) { ?>
<br><b><?php echo $row['product']; ?></b><br> <?php echo $row['category'];
}
}
?>
索引页
<form method="post" action="search.php">
<div class="form-group">
<textarea class="form-control" id="textarea" name="textarea" rows="15" placeholder="Eg:Milk Powder"></textarea>
</div>
<div class="col-md-8 col-xs-12 col-sm-7" style="background-color:#1b934d;margin-top: -14px;">
<h3 style="color:white;font-size: 21px;">To start shopping with the shoppinglist.</h3>
</div>
</form>
我需要它才能显示
手镯
手镯的所有产品
戒指
戒指的所有产品
项链
项链的所有产品