简体   繁体   中英

Filtering data from the database

In my database I have a post entity connected to category entity. I display the categories on my website using <p>$row_category['categoryname']</p> . I want to make them hyperlinks which will display the post in the chosen category. How to achieve that?

You will need to use some sort of identifier for the categories that is then looked up by the destination PHP and passed via GET. Then just wrap it in an <a>

<p><a href="handler.php?id=$row_category['categoryid']">$row_category['categoryname']</a></p>

In handler.php you would retrieve the id with:

$id=$_GET['id'];
<a href="desired link"><?php echo $row_category['categoryname']; ?></a>

我想这就是你想要的......

或以其他方式我们可以做同样的事情

<?php echo "<a href='goto.html'>".$row_category['categoryname']."</a>"; ?>

looks like you are using mySQL, so this should work.

<?php
while ($row_category = mysql_fetch_assoc($query)) { ?>
    <a href="desired link"><?php echo $row_category["categoryname"]; ?></a>
<?php } ?>

might i suggest you start on PDO, now when mySQL are getting outdated. :)

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