gpt4 book ai didi

php - 使用函数来简化 CMS 主题

转载 作者:行者123 更新时间:2023-11-29 09:09:34 25 4
gpt4 key购买 nike

我正在制作自己的 CMS。我有一些代码可以选择要在页面上回显的数据库行,如下所示:

$query = mysql_query("SELECT * FROM posts order by id desc") or die(mysql_error()); 

但是,每当我尝试将其放入函数中并调用该函数而不是使用那么长的代码行时,什么也没有发生。我是否缺少 PHP 函数的某些内容?

function posts() {
mysql_query("SELECT * FROM posts order by id desc") or die(mysql_error()); `
}
while($row = mysql_fetch_array(posts())) {
$id = $row['id'];
echo $id;
}

最佳答案

您需要返回结果:

function posts() {
return mysql_query("SELECT * FROM posts order by id desc") or die(mysql_error()); `
}

关于php - 使用函数来简化 CMS 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6039505/

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