gpt4 book ai didi

php - 返回wordpress中表中的DB查询结果

转载 作者:行者123 更新时间:2023-11-30 00:01:49 25 4
gpt4 key购买 nike

此脚本的工作原理如下,返回当前用户的“电影”数量。但我想更进一步,让页面在表格中显示所有电影名称“movie_names”和流派“genre”。我已经尝试了很多事情,但是在 WordPress 中执行此操作时遇到了一些麻烦。

<?php 
$user_ID = get_current_user_id();
global $wpdb;
?>
Movies: <?php
$results = $wpdb->get_results("SELECT count(*) as total from movies where ID = $user_ID");
print "<a href=\"http://example.com/active\">" .$results[0]->total ."</a><br>";

?>

最佳答案

明白了!这效果很好。 Howlin,当我来这里输入成功的代码时刚刚看到你的帖子,所以还没有尝试过你的。但这可能对其他人有帮助。谢谢!

<?php 
$user_ID = get_current_user_id();
global $wpdb;


$results = $wpdb->get_results("SELECT * FROM movies where ID = $user_ID");
if ($results) {
echo '<table>';
foreach ($results as $row) {
// Each $row is a row from the query
echo '<tr>';
echo '<td>' . $row->movie_name; '</td>';
echo '<td>' . $row->genre; '</td>';
echo '</tr>';
}
echo '</table>';
}
?>

关于php - 返回wordpress中表中的DB查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24965174/

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