我正在使用this数据库,我在PHP文件中创建了一个表,列出了所有这些值。我将我的“主题”值链接到一个应该显示“描述”的不同文件,但每次当我点击“主题”时,我都会从表格中的第一个输入中获得描述。
这是我显示表格的代码
<?php
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");
?>
<?php
ob_start();
include 'organize_meeting.php';
ob_end_clean();
$mysqli = new mysqli("localhost", "root", "", "users");
$curr_user = $loggedInUser->username;
mysql_connect('localhost', 'root', '');
mysql_select_db('users');
$query = "SELECT * FROM uc_messages WHERE `to` = '$curr_user'";
$records = mysql_query($query);
echo "
<body>
<div id='wrapper'>
<div id='top'><div id='logo'></div></div>
<div id='content'>
<h2>My Meetings</h2>
<div id='left-nav'>";
include("left-nav.php");
echo "
</div>
<div id='main'>
</div>
<div id='bottom'></div>
</div>
</body>
</html>";
?>
<table width = "600" border = "1" cellpadding = "1" cellspacing = "1">
<tr>
<th>From</th>
<th>Subject</th>
<th>Beginning of meeting</th>
<th>End of meeting</th>
</tr>
<?php
while($msgs = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$msgs['from']."</td>";
echo "
<td>
<a href = 'info.php' target = '_blank_'> ".$msgs['subject']." </a>
</td>
</html>";
echo "<td>".$msgs['TimeFrom']."</td>";
echo "<td>".$msgs['TimeTo']."</td>";
echo "<tr>";
}
?>
这是我的代码,可以显示描述
<?php
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");
?>
<?php
ob_start();
include 'organize_meeting.php';
ob_end_clean();
$mysqli = new mysqli("localhost", "root", "", "users");
$curr_user = $loggedInUser->username;
mysql_connect('localhost', 'root', '');
mysql_select_db('users');
$query = "SELECT * FROM uc_messages WHERE `to` = '$curr_user'";
$records = mysql_query($query);
echo "
<body>
<div id='wrapper'>
<div id='top'><div id='logo'></div></div>
<div id='content'>
<h2>About Meeting</h2>
<div id='left-nav'>";
echo "
</div>
<div id='main'>
</div>
<div id='bottom'></div>
</div>
</body>
</html>";
?>
<?php
$msgs = mysql_fetch_assoc($records);
echo "<p>".$msgs['from']."</p>";
echo "<p>".$msgs['description']."</p>";
echo "<p>".$msgs['TimeFrom']."</p>";
echo "<p>".$msgs['TimeTo']."</p>";
?>
我总是从数据库中获得相同的描述,尽管我点击了不同的输入。
答案 0 :(得分:2)
注意:您将
mysqli.*
和mysql
混合在一起,您必须将mysqli.*
转换为您拥有的整个查询。你必须修复你拥有的所有混合代码,然后你遵循我给出的代码。
以下示例我将在mysqli.*
的声明中给出,您必须对代码进行更改。
文件一:
您缺少传递主题的ID或要显示的<a>
标记中的自动增量ID。
因此,以下<a>
标记如下。
<强>替换强>
<td>
<a href = 'info.php' target = '_blank_'> ".$msgs['subject']." </a>
</td>
。通过强>
<td>
<a href = 'info.php?subject_id=".$msgs['id']."' target = '_blank_'> ".$msgs['subject']." </a>
</td>
文件二:
因此,您可以在此处获取我们已在<a>
标记中传递的请求,我们将对其进行操作。
$msgs = mysqli_fetch_assoc($records)
echo "<p>".$msgs['from']."</p>";
echo "<p>".$msgs['description']."</p>";
echo "<p>".$msgs['TimeFrom']."</p>";
echo "<p>".$msgs['TimeTo']."</p>";
删除这些行,因为它没有任何意义。您已使用mysqli
连接已连接到数据库。
mysql_connect('localhost', 'root', '');
mysql_select_db('users');
像这样更改查询,使其成为mysqli.*
方式。
$query = "SELECT * FROM uc_messages WHERE `id` = '".$_REQUEST['subject_id']."'";
$records = mysqli_query($mysqli,$query);