I'm trying to do links like: test.com/article.php?=$id where $id is from data base
$sql = "SELECT * FROM articles WHERE writer='$w_name' ";
$result = mysqli_query($conn, $sql);
$q = array();
$l = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$q[]=$row['header'];
$l[]=$row['id'];
}
}
So i have for example: $q=1,2,3 and $l=1st link name,2nd link name, 3d link name.
I tried to do that together this way, but it doesn't work correct:
<?
foreach($q as $header)
{
echo'<li>'.$header.'</li>';
}
?>
<?
foreach($l as $id)
{
echo "<a href='article.php?=$id'>".$header.'<br>'.'</a>';
}
?>
In this case i had 3 different links with the same name like:
<a href='article.php?=1'>1st link name</a>
<a href='article.php?=2'>1st link name</a>
<a href='article.php?=3'>1st link name</a>
Also i have tried :
<?
foreach($l as $id)
foreach($q as $header)
{ echo "<a href='article.php?=$id'>".$header.'<br>'.'</a>'; } ?>
But it gave me all combinations like:
<a href='article.php?=1'>1st link name</a>
<a href='article.php?=1'>2nd link name</a>
<a href='article.php?=1'>3d link name</a>
<a href='article.php?=2'>1st link name</a>
<a href='article.php?=2'>2nd link name</a>
<a href='article.php?=2'>3d link name</a>
<a href='article.php?=3'>1st link name</a>
<a href='article.php?=3'>2nd link name</a>
<a href='article.php?=3'>3d link name</a>
I'm new to php and mysql, and i don't know how to solve this problem