0

Hello,

I am trying to get this to loop through all the available items in a database and return the results.

<?php 
    $qry = mysqli_query($con,"SELECT * FROM `favorites` WHERE `username` = '$id'") or die(mysqli_error($con));

        while($rowa = mysqli_fetch_array($qry)) {
            $slugname = $rowa['slug_name'];
            $url = $rowa['slug'];
    echo '<a href="'.$url.'>'.$slugname.'</a>"';

    }
?>

I think i need a foreach loop, but not sure how todo it.

Thanks in advance

2
Contributors
4
Replies
11
Views
2 Years
Discussion Span
Last Post by patk570
1

Where is your connection string?

For your loop try this:

while($row = mysqli_fetch_array($qry)){
    echo '<a href="' . $row['slug'] . '">' . $row['slug_name'] .  '</a>';
}
0

My connecting string is attached above as an include. Is that going to return all results back to the user?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.