php - 来自数据库 ID 的元 OG 图像
问题描述
我有一个网站,有一个页面列出多个新闻,在单个新闻的详细页面中,我需要捕获 id_news 以放置单个新闻中的元 og 图像和元 og 标题。
试了很多代码都没有结果,总是显示黑页
我在页面顶部有这段代码:
<?php
$caatid=intval($_GET['cid']);
$fetch_sql = "SELECT titulonews, completonews, postimage FROM noticiaspt where id_news='$catid'";
while($fetch_row=mysql_fetch_array($fetch_result))
{
$titulonews = $fetch_row['titulinews'];
$postimage = $fetch_row['postimage'];
$completonews = $fetch_row['completonews'];
?>
<meta property="og:title" content="<?php echo $titulonews; ?>" />
<meta property="og:image" content="http://linktomysite.pt/admbo/postimages/<?php echo $postimage; ?>" />
<meta property="og:description" content="<?php echo $completonews; ?>" /> <?php } ?>
但是,在正文中,使用正确 ID 请求新闻的代码可以正常工作......
这是我尝试的其他代码:
<?php
$catid=intval($_GET['cid']);
$query=mysqli_query($con,"Select id_news,titulonews,completonews,postimage from noticiaspt where Is_Active=1 and id_news='$catid'");
while($row=mysqli_fetch_array($query)) {
?>
<meta property="og:title" content="<?php echo htmlentities($row['$titulonews']); ?>" />
<meta property="og:image" content="http://linktomysite/admbo/postimages/<?php echo htmlentities($row['$postimage']); ?>" />
<meta property="og:description" content="<?php echo htmlentities($row['$completonews']); ?>" /> <?php } ?>
我找不到问题。有什么帮助吗?
解决方案
有很多要谈的点
- 您希望当前页面有一个通知,但您正在使用 while() 最终将为您提供数据库返回的最后一行
- 这可能会破坏您的代码
<?php } ?>
推荐阅读
- arm - ARM Cortex M 检测调试器是处于运行模式还是调试模式
- ms-office - Office 插件 - 从 Excel 中启动 Word
- apache-spark - HIVE:插入查询失败并出现错误“java.lang.OutOfMemoryError:超出 GC 开销限制”
- python - 有没有办法在 Flask 中的 redirect() 之后从函数返回一个值?
- jmeter - 我想使用 Jmeter 脚本启动和停止 localhost 服务器(远程机器)
- android - 应用程序关闭时在后台播放视频声音(在通知栏中),就像 VLC 播放器一样
- c# - 无法使用 Sqlite 和 entityFramework (FileNotFoundException / SQLitePCLRaw.batteries_v2)
- python - 光学并行度
- javascript - 如何在 DHTMLX 甘特图中过滤多个部门
- list - 如何使用 perl 比较文本文件中两个不同数据库的每个元素?