我試圖做這樣的聯繫: test.com/article.php?=$id其中$ id與數據庫PHP + mysql.Dynamic網站,鏈接
$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'];
}
}
所以我有例如: $ q = 1,2,3和$ l =第1個鏈接名稱,第2個鏈接名稱,3d鏈接名稱。
我試圖這樣做在一起,但它不工作正確的:
<?
foreach($q as $header)
{
echo'<li>'.$header.'</li>';
}
?>
<?
foreach($l as $id)
{
echo "<a href='article.php?=$id'>".$header.'<br>'.'</a>';
}
?>
在這種情況下,我不得不與像同名3個不同的環節:
<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>
而且我曾嘗試過:
<?
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>
我是新來的php和mysql,我不知道如何解決這個問題
問:爲什麼要讓它返回'?= xxx'?獲取方法需要類似'?var = xxx'的東西 - 我想知道你將如何訪問這些鏈接。即:'if(isset($ _ GET ['xxx'])&&($ _GET ['xxx'] ==「1」)){...}' – 2015-02-05 20:45:12