我在php中得到了这个错误。我不明白为什么......
以下是我的连接建立方式:
<?php
$hostname_QASite = "localhost";
$database_QASite = "qasite";
$username_QASite = "root";
$password_QASite = "";
$QASite = mysql_pconnect($hostname_QASite, $username_QASite, $password_QASite) or trigger_error(mysql_error(),E_USER_ERROR);
?>
我的查询如下:
mysql_select_db($database_QASite, $QASite) or die(mysql_error());
$query_get_all_topics = "SELECT topic_id, title FROM topic";
$get_all_topics = mysql_query($query_get_all_topics, $QASite) or die(mysql_error());
$row_get_all_topics = mysql_fetch_assoc($get_all_topics);
$totalRows_get_all_topics = mysql_num_rows($get_all_topics);
然后我遍历row_get_all_topics ...
代码有什么问题?
编辑:
当我尝试在数据库中的不同结果上循环2次时,我得到了该错误。
更新:
<body>
<br/><br/><br/><br/><br/><br/><br/>
<div align="center">
<ul id="navlist">
<li> <a href="/QASite/Admin/create_topic.php">צור נושא</a></li>
<li> <a href="">ראה קשרים</a></li>
</ul>
<?php do { ?>
<table border="1">
<tr>
<td>
<table width="100%" border="1" >
<tr>
<td width="90%" align="right">
<?php echo $row_get_all_topics['title']; ?>
</td>
<td width="10%">
:שם נושא
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>
<a href=""></a>
<a href="/QASite/Admin/update_topic.php?topic_id=<?php echo $row_get_all_topics['topic_id']; ?>"></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
//$result=$mysql_query("SELECT title, sub_topic_id FROM sub_topic WHERE topic_id=".$row_get_all_topics['topic_id']) or die(mysql_error());
$result="";
if($row=mysql_fetch_array($result))
{
do
{
?>
<table >
<tr>
<td>
<?php echo $row['title']; ?>
</td>
<td>
:תת נושא
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<a href="/QASite/Admin/update_subtopic.php?topic_id=<?php echo $row_get_all_topics['topic_id']; ?>&subtopic_id=<?php echo $row['title']; ?>">עדכן</a>
</td>
<td>
<a href="/QASite/Admin/update_subtopic.php?subtopic_id=<?php echo $row['title']; ?>">מחק</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><a href="/QASite/Admin/create_subTopic.php?topic_id=<?php echo $row_get_all_topics['topic_id']; ?>"></a></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
**}while($row=mysql_fetch_assoc($result));** 1 FIRST LOOP
}//end suptopic search
?>
<?php **} while ($row_get_all_topics = mysql_fetch_assoc($get_all_topics)); ?>** 2ND LOOP
一旦我添加这一行,在循环内查询数据库,页面就会显示错误..
$result=$mysql_query("SELECT title, sub_topic_id FROM sub_topic WHERE topic_id=".$row_get_all_topics['topic_id']) or die(mysql_error());