我试图从一个函数返回两个结果,但只有第一个结果显示在我的页面上。
这是我的功能:
function latestcomment($forum_topics){
$recent = mysql_query(" SELECT created, owner, topic_id
FROM forum_comments
WHERE topic_id = '".mysql_real_escape_string($forum_topics['topic_id'])."'
ORDER BY created DESC
LIMIT 1 ");
$mostrecent = mysql_fetch_array($recent);
$time = $mostrecent['created'];
$name = $mostrecent['owner'];
return $time;
return $name;
}
然后我这样打电话
<?php echo latestcomment($forum_topics); ?>
我从中调用的表如下所示:
+-------+----------+---------------------+------------+
| id | body | created | owner |
+-------+----------+---------------------+------------+
| 1 | hello | 2019-12-01 15:50:27 | name1 |
| 2 | World | 2019-12-01 15:50:32 | name2 |
| 3 | Hi | 2019-12-01 15:51:43 | name3 |
| 4 | Over | 2019-12-01 10:20:30 | name4 |
+-------+----------+---------------------+------------+
此外,我想将返回函数的 created(DATETIME) 部分传递给如下内容:
<?php
$date = date_create($forum_topics['$time']) ;
echo date_format($date, 'F j, Y'); echo"<br>";
echo date_format($date, 'g:i A');
?>
只使用一个查询?
我怎样才能做到这一点 ?
谢谢你。