[英]Displaying based on Results in Mysql Query
I have an orders table in mysql and in that for some orders I set particular order status like 'review'. 我在mysql中有一个订单表,对于某些订单,我设置了特定的订单状态,例如“评论”。 I want to setup a way if any order placed by a particular customer(first and last name) for whom i have previously set order status as 'review' to display a warning in the list. 我想设置一种方式,如果某个特定客户(名字和姓氏)下的任何订单(我先前已将其订单状态设置为“审阅”)在列表中显示警告。
$sql = "select * from order where firstname = ".$firstname." AND lastname = ".$lastname." AND order_status = 'review';";
$SQLresult = mysql_query("$sql", $DBcon_MySQL);
while($row = mysql_fetch_array($SQLresult)) {
foreach($row as $row){
$result = "warning!";
echo $result;
}
}
The above code does not display anything. 上面的代码不显示任何内容。 please let me know how to fix this. 请让我知道如何解决此问题。
[EDIT After Applying Answer] [应用答案后进行编辑]
This is how i am using it. 这就是我使用它的方式。
<td width="200">
<?
$sql = "select * from cust_order where firstname = '$firstname' AND lastname = '$lastname' AND order_status = 'review'";
$SQLResult = mysql_query("$sql", $DBcon_MySQL);
while($row = mysql_fetch_array($SQLResult )) {
//$result;
foreach($row as $row ){
//$result="";
$result = "Warning!";
}
?>
<p><? echo $result;?></p>
<?} ?>
</td>
How should i insert a check that it should display warning only once No matter how many orders from single customer are marked as review, display warning only once? 我应该如何插入只显示一次警告的支票?无论单个客户有多少订单被标记为复审,都只显示一次警告?
try this, 尝试这个,
$sql = "SELECT
*
FROM
`order`
WHERE
firstname = '$firstname' AND lastname = '$lastname' AND
order_status = 'review' LIMIT 1";
$SQLresult = mysql_query($sql, $DBcon_MySQL);
while($row = mysql_fetch_array($SQLresult)) {
foreach($row as $row){
$result = "warning!";
echo $result;
}
}
Please be informed that mysql functions are deprecated and not recommended. 请注意,不建议使用mysql函数,不建议这样做。 USE MySQLi or PDO instead. 请改用MySQLi或PDO。 have a reference from following queries. 有以下查询的参考。
http://php.net/manual/en/book.mysqli.php http://php.net/manual/zh/book.mysqli.php
http://php.net/manual/en/book.pdo.php http://php.net/manual/zh/book.pdo.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.