Php 注意:未定义变量:table
我知道这个问题被问了很多次,但仍然。。我不是专家。下面是我的代码:Php 注意:未定义变量:table,php,Php,我知道这个问题被问了很多次,但仍然。。我不是专家。下面是我的代码: <?php $result=mysqli_query($con, $sql)or die(mysqli_error($con)); $search_result = ""; $search_result .= " <table border='0' cellspacing='0' cellpadding='0'><tr>"; while($row=mysqli_fet
<?php
$result=mysqli_query($con, $sql)or die(mysqli_error($con));
$search_result = "";
$search_result .= " <table border='0' cellspacing='0' cellpadding='0'><tr>";
while($row=mysqli_fetch_array($result))
{
$id=$row['id'];
$department=$row['department'];
$name=$row['name'];
$extension=$row['extension'];
$hpno=$row['hpno'];
$staff_no=$row['staff_no'];
$birthdate=$row['birthdate'];
$position=$row['position'];
$email=$row['email'];
$image=$row['image'];
$status=$row['status'];
$search_result .= " <td height='250' valign='top'><img src='" . $image . "'> </td>
<td><table border='0' width='250'>
<tr><td height='40' valign='top'><font size='3'><strong>" . $staff_no . " " . $name . "</strong></font></td></tr>
<tr><td height='32' valign='top'><i>" . $position . "</i></td></tr>
<tr><td height='32' valign='middle'><font color='blue'>" . $email . "</font></td></tr>
<tr><td height='32' valign='middle'><img src='mobile.png'> " . $hpno . " | Office Ext : <strong>" . $extension . "</strong></td></tr>
<tr><td height='32' valign='middle'>Department : " . $department . "</td></tr>
<tr><td height='32' valign='middle'>DOB : " . $birthdate . "</td></tr>
<tr><td height='32' valign='middle'>Status : " . $status . "</td></tr>
</table>
</td>
<td width='20'> </td>";
$table=$table + 1;
if ($table=='3')
{
$search_result .= "</tr><tr>";
$table=0;
}
}
$search_result .= "</table>";
$search_result .= "<br />";
echo $search_result;
?>
<center><?=$pagination?></center>
您应该使用此
$table=0;
$table++;
if ($table==3)
{
$search_result .= "</tr><tr>";
$table=0;
}
$table=0;
$table++;
如果($table==3)
{
$搜索结果=“”;
$table=0;
}
这是一个警告,您可以忽略php文档中的设置错误报告(E_error | E_PARSE)代码>
好吧,忽略通知从来都不是一个好主意,我们解释错误。在本例中,您正在调用尚未声明的$table变量。
您需要这样声明:
$table = 0;
$table=$table + 1;
if ($table=='3')
{
$search_result .= "</tr><tr>";
$table="0";
}
$table=0;
$table=$table+1;
如果($table='3')
{
$搜索结果=“”;
$table=“0”;
}
在使用$table变量之前,您是否定义了它?好像你没有。我想应该是这样的
$table = some value; //first define it, and then use
然后
$table=$table + 1;
if ($table=='3')
{
$search_result .= "</tr><tr>";
$table="0";
}
$table=$table+1;
如果($table='3')
{
$搜索结果=“”;
$table=“0”;
}
在第一行$table=$table+1
,在RHS上使用之前是否定义了$table
。如果没有,你会明白这并不能解决你的问题(你得到的答案会),但我只想指出,你不应该用引号括起整数。引号意味着字符串(即使这在像PHP这样的松散类型语言中有效)。这是一个糟糕的做法。谢谢你指出了这一点。当我将$table=0放在第一行时,我的数据库只返回3条记录,而不是所有记录。正如我在分页页面中定义的,每页的数据限制是9。我只是编辑我的问题以更好地理解。介意分享一下你关于改变条件的想法吗?假设我的分页将显示每页9条记录(3*3)。当我定义$table=某个值时;我的页面在一行中显示9条记录,而不是3*3use$table==3(不带引号)。它是从db返回最后3条记录还是返回前3条记录?确实没有重写$table变量吗?my pagination.php define$limit=9,即每页显示9条记录。在我定义$table=0之前;页面按照我的要求显示记录3行和3列,但在我定义$table=0之后;我的页面在一行中显示9条记录,这是因为只有当$table==3时才关闭行。页面将垂直显示9条记录,而不是我在分页中定义的每页3*3条记录