我试图解决这个问题好几天但仍然无法解决。我试图使用mysqli_num_rows($result)>0
进行if语句,但它无法正常工作。这听起来很奇怪。如果result>0
,它将显示记录(工作正常)否则不会显示任何记录(这也正常工作)但表格仍然显示。我不知道为什么(如果结果返回空,表格不会出现)。另一个相关的问题是,当没有记录时,似乎出现3个值(列图下没有图像值,列下的日期{ {1}},在“终止成员资格”列下删除。任何帮助将不胜感激。我无法获得"没有图像价值","日期"和"删除"当结果返回空时离开。我试图让整个表格不显示,以便列(也不会显示,但它无法正常工作)。
userpage.php
Dat Reg
包含文件(run.php)
<p align="left">A. YOUR RECORDS </p>
<p align="left">
<?php
echo "<tr><td></tr></td>";
if(mysqli_num_rows($result)>0){
echo "<table cellpadding=10 border=0 id='secondtable'>";
echo "<tr><td bgcolor=#698C00 class='white'>"."Membership"."</td>".
"<td bgcolor=#698C00 class='white'>"."Title"."</td>".
"<td bgcolor=#698C00 class='white'>"."Location"."</td>".
"<td bgcolor=#698C00 class='white'>"."Phone"."</td>".
"<td bgcolor=#698C00 class='white'>"."Picture"."</td>".
"<td bgcolor=#698C00 class='white'>"."Date Reg"."</td>".
"<td bgcolor=#698C00 class='white'>"."Terminate Membership?"."</td></tr>";
if(mysqli_num_rows($result)>0){
while( $row = $result->fetch_array(MYSQLI_ASSOC)){
$showdateua=$row['dateua'];
$showdateua=date('d-m-Y',strtotime($showdateua));
echo "<tr><td bgcolor=#DCDCDC>".$_SESSION['Membership']=$row['Membership'].
"</td><td bgcolor=#DCDCDC>".$_SESSION['Title']=$row['Title'].
"</td><td bgcolor=#DCDCDC>".$_SESSION['location']=$row['location'].
"</td><td bgcolor=#DCDCDC>".$_SESSION['adphone']=$row['adphone'].
"</td><td bgcolor=#DCDCDC>".
'<img src="'.$_SESSION['image1']=$row['image1'].'"alt="No image"style="width:100px;height:100px;"/>'.
"</td><td bgcolor=#DCDCDC>".$_SESSION['dateua']=$showdateua.
"</td><td bgcolor=#DCDCDC>"."<a href=\"rundelup.php?idadv=".$row['idadv']."\">"."Delete"."</a></td></tr>";
}
}
echo "</table>";}
else
{
if(mysqli_num_rows($result)===0)
{echo "No records";}
}?>
<?php
if(isset($_SESSION['id'])){
if (isset($result)){
if(mysqli_num_rows($result)>0){
echo "<table>";
$page=(int)$page;
if($page>$tpages)
{$page=$tpages;}
if($page<1)
{$page=1;
}
if($page==1){
echo "";}
else
{
//go to first page
echo "<tr><td><a href='?page=1'class='button'>FIRST</a></td>";
}
if($page>1)
{
//go to previous page to show previous 3 items.
echo "<td><a href='?page=".($page-1)."'class='button'><<</a></td>";
}
echo "<ul class='page'>";
for($i=max($page-4,1);$i<=max(1,min($tpages,$page+4));$i++)
{
if($i==$page){
echo "<td><class='current'>".$i."</td>";
}
else{
echo "<td><a href='?page=".$i."'>".$i."</a></td>";}
//echo "<tr><td><a href=useradacc.php?page=".$i.">".$i."</a></td></tr>";
}
echo "</ul>";
if($page!=$tpages)
{
//go to next page to show next 3 items.
echo "<td><a href='?page=".($page+1)."'class='button'>>></a></td>";
}
if($page==$tpages)
{
echo "";}
else{
//go to last page
echo "<td><a href='?page=".($page=$tpages)."'class='button'>LAST</a></td></tr>";
}
echo "</table>";
}
}}
else
{echo "Insert record";
}
?>
答案 0 :(得分:0)
您的代码可能还有其他错误。 确保通过查看输出来获得有效的SQL查询。
$advert = "SELECT u.*,ua.* FROM uskkk u LEFT JOIN uaddd ua ON u.id=ua.id WHERE u.id='".$id."'ORDER BY dateua DESC LIMIT $start,$reclimit";
$statement = $conn->query($advert);
var_dump($statement);
查看结果?
准备好的声明
使用?
符号表示动态参数,并使用bind_param()
将其变量绑定到sql查询之外。
$stmt= $conn->prepare("SELECT u.*,ua.* FROM uskkk u LEFT JOIN uaddd ua ON u.id=ua.id WHERE u.id= ? ORDER BY dateua DESC LIMIT ?,?");
$stmt->bind_param("iii", $id, $start, $reclimit);
$stmt->execute();
$result = $stmt->get_result();
您可以在之后获取结果
while($row = $result->fetch_array(MYSQLI_ASSOC)){
var_dump($row);
}
确保您知道要绑定的变量类型
i =对应的变量类型为整数
d =对应的变量类型为double
s =对应的变量具有类型字符串
b =相应的变量是blob,将以数据包形式发送
来自http://php.net/manual/en/mysqli-stmt.bind-param.php
或仅使用mysqli::query
$stmt= $conn->query("SELECT u.*,ua.* FROM uskkk u LEFT JOIN uaddd ua ON u.id=ua.id WHERE u.id='".$id."'ORDER BY dateua DESC LIMIT $start,$reclimit");
while($row = $result->fetch_array()){
var_dump($row);
}
像这样更改表格结构
echo "<table cellpadding=10 border=0 id='secondtable'>";
echo "<tr><td bgcolor=#698C00 class='white'>" . "Membership" . "</td>" . "<td bgcolor=#698C00 class='white'>" . "Title" . "</td>" . "<td bgcolor=#698C00 class='white'>" . "Location" . "</td>" . "<td bgcolor=#698C00 class='white'>" . "Phone" . "</td>" . "<td bgcolor=#698C00 class='white'>" . "Picture" . "</td>" . "<td bgcolor=#698C00 class='white'>" . "Date Reg" . "</td>" . "<td bgcolor=#698C00 class='white'>" . "Terminate Membership?" . "</td></tr>";
if (mysqli_num_rows($result) > 0) {
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$showdateua = $row['dateua'];
$showdateua = date('d-m-Y', strtotime($showdateua));
echo "<tr><td bgcolor=#DCDCDC>" . $_SESSION['Membership'] = $row['Membership'] . "</td><td bgcolor=#DCDCDC>" . $_SESSION['Title'] = $row['Title'] . "</td><td bgcolor=#DCDCDC>" . $_SESSION['location'] = $row['location'] . "</td><td bgcolor=#DCDCDC>" . $_SESSION['adphone'] = $row['adphone'] . "</td><td bgcolor=#DCDCDC>" . '<img src="' . $_SESSION['image1'] = $row['image1'] . '"alt="No image"style="width:100px;height:100px;"/>' . "</td><td bgcolor=#DCDCDC>" . $_SESSION['dateua'] = $showdateua . "</td><td bgcolor=#DCDCDC>" . "<a href=\"rundelup.php?idadv=" . $row['idadv'] . "\">" . "Delete" . "</a></td></tr>";
}
} else {
echo "No records";
}
echo "</table>";