我發佈了一個關於我的網站的代碼。在這段代碼中,我想更新數據庫中的行,如果用戶更改了網站表單上主題的名稱。除sql部分外,一切正常。我的意思是這裏的部分:「LIMIT 1 OFFSET'$ x'」這部分sql代碼由於某種原因並不好,但我不知道爲什麼。我在xampp phpmyadmin中測試過它,但它的工作原理錯了。我對sql部分有困難
<?php
$sql = "SELECT topicname, username, created, COUNT(commentid)
FROM user, topic, comment
WHERE topic.topicid = comment.whichtopic
AND user.userid = topic.owner
AND user.username = '" . $_SESSION['user_name '] . "'
GROUP BY topicname ";
$lekerdezes = mysql_query($sql);
$num_rows = mysql_num_rows($lekerdezes); ?>
<?php
if (isset($_POST['delete']))
{
if (!empty($_POST['forumnev']))
{
for ($x = 0; $x < $num_rows; $x++)
{
foreach ($_POST['forumnev'] as $selected)
{
$seged = mysql_query("SELECT created FROM topic WHERE
created IN (SELECT created FROM user, topic, comment WHERE topic.topicid = comment.whichtopic
AND user.userid = topic.owner AND user.username = '" . $_SESSION['user_name '] . "'
GROUP BY topicname ORDER BY created)
LIMIT 1 OFFSET '$x'");
if (!$seged)
{
echo mysql_error();
}
$seged2 = mysql_fetch_array($seged);
$seged2 = $seged2[0];
if (!$seged2)
{
echo mysql_error();
}
$sql = mysql_query("UPDATE topic SET topicname = '$selected' WHERE created = '$seged2'");
}
}
header("Location: topicedit.php");
}
}
?>
全部採用mysqli_ *首先,因爲mysql_ *是depricated,你可以指出在哪一行,你有錯誤。? –
'@ david'你可以複製粘貼我的代碼並檢查一次。 –