如果在查询选择中找不到结果,我想要的是什么,我想显示其他函数:
else {
$html .= 'You have not added stock at all';
}
因为在这种情况下我使用了html
的字符串,我不知道如何回应else语句。
我的代码或多或少现在看起来像这样(我已经删除了许多部分,因为它太长了)
<?php
include("../actions/config.php");
$resultsClaim = $mysqli->query("SELECT");
$orders = array();
$html = '';
if ($resultsClaim) {
while($obj = $resultsClaim->fetch_object()) {
$orders[$obj->id_cart][$obj->items] = array('status' => $obj->status ...);
}
foreach ($orders AS $order_id => $order) {
$orderCount = count($order);
$html .= '<tbody><tr><td rowspan="' . count($order) . '">' . $order_id . '</td>';
$row = 1;
foreach ($order AS $item => $data) {
if ($row > 1) { $html .= '</tr><tr>'; }
$html .= '<td>' . $item . '</td>';
$row++;
}
$html .= '<div>
<div class="member-popUpeStock'.$data['id'].' member-PopUp">
<div class="member-PopUp-box">
<a href="" title="Close" class="close">X</a>
<div class="tablePopUp">
<div class="table-row">
<div class="col">: '.$data['method'].' </div>';
///HERE WHERE I WANT TO DO THAT////
else {
echo 'Nothing';
}
echo $html;
?>
请有人帮助我!提前致谢。
答案 0 :(得分:2)
由于您将订单数量转换为变量,您可以直接使用它来查看订单是否存在。
$orderCount = 0; //Define orderCount in the beginning.
//Rest of the code, till foreach
foreach(){
//Rest of the code here
}
if(intval($orderCount) <= 0) //Using intval, for the case the for loop is not executed at all
{
$html = "Nothing";
}
这里你不需要将它连接到$ html,因为如果订单存在则显示表内容,否则你显示&#34; Nothing&#34;。 所以$ html要么拥有表格内容,要么“#34; Nothing&#34;。
”希望这有帮助。
答案 1 :(得分:0)
首先得到$orders
if (! empty($orders)) {
foreach ($orders AS $order_id => $order) {
// YOUR CODE HERE
}
}
else {
$html .= 'Nothing'; // Append your `no records found` message to the `$html` variable:
}
答案 2 :(得分:0)
foreach ($orders AS $order_id => $order) { } else {}
所以&#34;}&#34; foreach循环缺少。希望它能为你效劳。如果您需要进一步的帮助,请告诉我。
答案 3 :(得分:0)
试一试
<?php
include("../actions/config.php");
$resultsClaim = $mysqli->query("SELECT");
$orders = array();
$html = '';
if (!empty($resultsClaim)) {
while ($obj = $resultsClaim->fetch_object()) {
$orders [$obj->id_cart][$obj->items] = array('status' => $obj->status);
}
foreach ($orders AS $order_id => $order) {
$orderCount = count($order);
$html .= '<tbody><tr><td rowspan="' . count($order) . '">' . $order_id . '</td>';
$row = 1;
foreach ($order AS $item => $data) {
if ($row > 1) {
$html .= '</tr><tr>';
}
$html .= '<td>' . $item . '</td>';
$row++;
}
$html .= '<div>
<div class="member-popUpeStock' . $data['id'] . ' member-PopUp">
<div class="member-PopUp-box">
<a href="" title="Close" class="close">X</a>
<div class="tablePopUp">
<div class="table-row">
<div class="col">: ' . $data['method'] . ' </div>';
}
}
///HERE WHERE I WANT TO DO THAT////
else {
echo 'Nothing';
}
echo $html;
?>