gpt4 book ai didi

mysql - 无法使用 SQL 表显示帖子标题

转载 作者:行者123 更新时间:2023-11-29 00:53:40 27 4
gpt4 key购买 nike

我正在尝试在修改/删除页面中显示标题列表。它们加载正常,因为我得到了正确数量的行,但出于某种原因我无法打印文本。

这是与问题对应的函数。

function manage_content()
{
echo '<div id="manage">';
$sql = "SELECT * FROM content";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)): ?>
<div>
<h2 class="title"><?php $row['title'] ?></h2>
<span class="actions"><a href="#">Edit</a> | <a href="#">Delete</a></span>
</div> <?php
endwhile;
echo '</div>'; //End of Manage Div

}

这是完整的代码:

<?php

class blog {
private $host;
private $username;
private $password;
private $db;
private $link;

public function __construct($host, $username, $password, $db){
$this->db = $db;
$this->link = mysql_connect($host, $username, $password, $db);
mysql_select_db($this->db, $this->link) or die (mysql_error());
}


function get_content($id=''){
if($id !=NULL):
$id = mysql_real_escape_string($id);
$sql = "SELECT * FROM content WHERE id = '$id'";
$return = '<p><a href="index.php">Vover al Indice</a></p>';
else:
$sql = "SELECT * FROM content ORDER by id DESC";
endif;

$res = mysql_query($sql) or die (mysql_error());

if(mysql_num_rows($res) !=NULL):
while($row = mysql_fetch_assoc($res)){
echo '<h1><a href="index.php?id='.$row['id'].'">'.$row['title'].'</a></h1>';
echo '<p>'.$row['body'].'</p>';
}
else:
echo '<p>Oops, post not found!</p>';
endif;
if(isset($return)){
echo $return;
}
}

function add_content($p){
$title = mysql_real_escape_string($p['title']);
$body = mysql_real_escape_string($p['body']);

if(!$title OR !$body):
if(!$title):
echo "<p>You have to fill the title.</p>";
endif;
if(!$body):
echo "<p>You have to fill the body.</p>";
endif;
echo '<p><a href="add-content.php">Try again!</a></p>';
else:
$sql = "INSERT INTO content VALUES (null, '$title', '$body')";
$res = mysql_query($sql) OR DIE (mysql_error());
echo "Added sucessfully!";
endif;

}

function manage_content()
{
echo '<div id="manage">';
$sql = "SELECT * FROM content";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)): ?>
<div>
<h2 class="title"><?php $row['title'] ?></h2>
<span class="actions"><a href="#">Edit</a> | <a href="#">Delete</a></span>
</div> <?php
endwhile;
echo '</div>'; //End of Manage Div

}

}// End of Class
?>

最佳答案

您忘记了 manage_content() 函数中的 echo:

<?php $row['title'] ?>

应该是:

<?php echo $row['title']; ?>

无论如何,这就是问题的一部分。

关于mysql - 无法使用 SQL 表显示帖子标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7169319/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com