无法链接<a href="#"> W/ PHP code

时间:2018-04-20 20:08:06

标签: php mysql

I tried to link $child['id'] but can't do it. Link is removed on line 13. Can anyone tell me correct way to generate category link on click?

<!-- fetch parent categories -->
<?php
while ($parent = mysqli_fetch_assoc($parentquery)) : ?>

<?php
$parent_id=$parent['cat_id'];?>

<!--fetch sub-categories-->
<?php
$sql2 = "SELECT * FROM categories WHERE cat_parent = '$parent_id'";
$child_query = $db->query($sql2); // database object
?>

<div class="col-menu col-md-3">
<h6 class="title"><?php echo $parent['cat_name'] ?></h6>

<div class="content">
<ul class="menu-col">
<?php while($child = mysqli_fetch_assoc($child_query)) : ?>

Now I want to link each category on the below. Loops works fine. I am seeing category names but no link. Please help

<li> <a href='#'>
<?php echo $child['cat_name']; ?></a></li>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php endwhile; ?>

2 个答案:

答案 0 :(得分:0)

你需要在href中传递它

<li> 
   <a href='<?php echo $child['link'];?'>
       <?php echo $child['cat_name']; ?>
   </a>
</li>

如果你的href为空,请尝试这个,然后你应该添加

<a href='"<?php echo $child['link'];?>"'> // double quotes

答案 1 :(得分:0)

您应该将ID传递给href

<a href='<?=$child['id'];?>'>