简体   繁体   中英

Generate HREF link depending on value in MySQL table row

I have the following PHP, my question is; how can I make the href generate itself based on the value of $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>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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