gpt4 book ai didi

php - 在 php 中获取 url id 并在 html 中显示结果

转载 作者:太空宇宙 更新时间:2023-11-03 10:51:47 25 4
gpt4 key购买 nike

您好,我编写这段代码是为了从 url 获取新闻 ID 并显示存储在 mysql 中的该 ID 的新闻结果。我不知道我做错了什么。但我得到任何输出。我还测试了我的查询,它在 mysql 中运行良好。我正在做一些小错误,它无法识别可能是某处的语法或引用。谢谢。这是我的网址:

http://autodo/admin/news.php?id=2043

这是我的代码:

    <?php
$ID=$_GET['id'];
$sql=" SELECT DISTINCT ad_news.datum, ad_news_texte.text, ad_news_texte.headline, ad_news_texte.id
FROM autodo.ad_news_texte, autodo.ad_news
WHERE ad_news_texte.id =".$ID."
GROUP BY ad_news_texte.text, ad_news_texte.headline, ad_news_texte.id";
echo $sql_select=mysql_query($sql);
if($row = mysql_fetch_assoc($sql_select)){
$news_id= $row['id'];
$news_datum= $row['datum'];
$news_text= $row['text'];
$news_headline= $row['headline'];
?>
<div class="welcome-rahmen lng toggleNews" id="<?= $news_id ?> ">
<p class="welcome-breadcrump"><?= $news_datum ?></p>
<p class="welcome-subheadline"><?= $news_headline ?></p>
<div class="newsText">
<?= $news_text ?>
</div>
</div>
<? } ?>

最佳答案

您应该通过 连接 $ID 和 sql 字符串。

例如:

 $sql="   SELECT DISTINCT ad_news.datum, ad_news_texte.text, ad_news_texte.headline, ad_news_texte.id
FROM autodo.ad_news_texte, autodo.ad_news
WHERE ad_news_texte.id =".$ID."
GROUP BY ad_news_texte.text, ad_news_texte.headline, ad_news_texte.id";

关于php - 在 php 中获取 url id 并在 html 中显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24307418/

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