gpt4 book ai didi

php - mysql查询熨烫网页上的一个搜索结果?

转载 作者:行者123 更新时间:2023-11-29 14:06:32 24 4
gpt4 key购买 nike

我的查询打印在网页上

SELECT * FROM products WHERE (product_name like '%meat%' OR description like '%meat%' OR ingradients like '%meat%') AND hide!=1 ORDER BY id ASC 

如果我在 mysql 中运行相同的查询,它会显示 2 个结果,而我的 php 循环代码则仅显示一个结果,

我的PHP代码

<?php       

$keyword=mysql_real_escape_string($_GET['Keyword']);

$query2 = "SELECT * FROM products WHERE (product_name like '%$keyword%' OR description like '%$keyword%' OR ingradients like '%$keyword%') AND hide!=1 ORDER BY id ASC ";


echo $query2 ;

$result2 = mysql_query($query2) or die('Error, query failed2');
if (mysql_num_rows($result2)>0){
mysql_data_seek($result2, 0);

$row2 = mysql_fetch_array($result2, MYSQL_ASSOC)

?>
<ul id="product-listing">
<?php

$i=1;

while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)){ ?>
<li <?php $i; if ($i%3==0) {echo "class=\"last\"";} ?>>
<div class="img">
<?php if ( $row2['new'] ==1 ) { ?>
<div class="new"><img src="images/new.png" width="18" height="41" /></div>
<?php } ?>
<a href="product-details.php?refID=<?php echo $row2['id']; ?>"> <img src="images/products/284X190/<?php echo $row2['image_1']; ?>" width="284" height="190" alt="" title="" /></a> </div>
<div class="name"><?php echo $row2['product_name']; ?></div>
<form action="" method="post">
<div class="price">Price:
<?php if ( $row2['market_price'] !=0 ) { ?>
<span> $<?php echo $row2['market_price']; ?> </span>
<?php } ?>
$<?php echo $row2['price']; ?></div>
<div class="add-to-cart">
<input type="image" src="images/btn-1.jpg" />
</div>
<div class="clear"></div>
</form>
</li>
<?php $i++; } ?>
</ul>
<?php } else { ?>
No Products,
<?php } ?>

最佳答案

您应该在 php 中使用 while 循环。

while($item = mysql_fetch_assoc($query))
{
print_r($item); // echo out whatever you need to for each item returned
}

关于php - mysql查询熨烫网页上的一个搜索结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14259954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com