META OG IMAGE from Database ID



我有一个网站,有一个页面列出多个新闻,在单个新闻的详细页面,我需要捕获id_news从单个新闻中放置元图像和元标题。

我试了很多代码,但从来没有得到的结果,总是显示一个黑色的页面

我在页面顶部有这段代码:

<?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 } ?>
我找不到问题。任何帮助吗?

有很多可谈的

  1. 您期望当前页面的单个通知,但您正在使用while(),最终将获得您的数据库返回的最后一行
  2. 这可能会破坏你的代码<?php } ?>

最新更新