简体   繁体   English

根据MySQL表行中的值生成HREF链接

[英]Generate HREF link depending on value in MySQL table row

I have the following PHP, my question is; 我有以下PHP,我的问题是; how can I make the href generate itself based on the value of $row['category']? 我怎样才能使href根据$ row ['category']的值生成自身? If anything is unclear, please let me know. 如果有任何不清楚的地方,请告诉我。

<?php
    echo "<div class=News>";
$q = "SELECT * FROM post ORDER BY newsno DESC";
$r = mysqli_query($mysqli, "$q");
if($r)
{

while($row=mysqli_fetch_array($r)){
    echo "<form action=index.php method=post>";
    echo "<div class=Container>";
    echo "<div class=Newsheader>";
    echo "<h7>";
    echo $row['newstopic'];
    echo "</h7>";
    echo "</div>";
    echo "<a href=image.php?newsno=".$row['newsno']." data-lightbox=roadtrip><img src=image.php?newsno=".$row['newsno']." width=180 height=180/></a>";
    echo "<div class=tb>";
    echo nl2br(substr ($row['newsinfo'], 0, 50));
    echo "<a href='This/Is/My/problem"."'> ...Read more</a>";
    echo "</div>";
    echo "</div>";
    echo "<div class=newsfooter>";
    echo 'Category: ' . $row['category']; 
    echo "</div>";
    echo "</br>";
    echo "</br>";
    echo "</form>";
}
echo "</div>";

}

else
{
echo mysqli_error();
}

?>

如果您要根据类别创建动态网址,则需要添加

echo '<a href="https://www.vg.no/'.$row['category'].'"> ...Read more</a>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM