2017-01-23 56 views
2

我有一個頁面,我將mysql中的數據調用到表中。我試圖創造一種情況,他們可以點擊桌子上的日期,並將它們鏈接到另一個頁面。下面是我想這如何在錨定標記中調用php變量

<a href="edit.php">'.$row['post_date'].'</a> 

是我的工作

$q = "SELECT*FROM forum"; 
$r = mysqli_query($dbc,$q); 
if (mysqli_num_rows($r)>0) 
{ 
    echo'<table><tr><th>Posted By</th> 
    <th>Subject</th><th id="msg">Message</th></tr>'; 
    while ($row=mysqli_fetch_array($r,MYSQLI_ASSOC)) 
    { 
     echo'<tr> 
     <td>'.$row['first_name'].''.$row['last_name'].'<br> 
            '.$row['post_date'].'</td> 
     <td>'.$row['subject'].'</td><td>'.$row['message'].'</td> 
     </tr>'; 
    } 
    echo '</table>'; 
} 
else 
{echo '<p>There are currently no messages.</p>';} 

我試圖把錨標籤上的代碼

'.$row['post_date'].' 

的代碼,但它並沒有工作

回答

2

試試這個:

<a href="edit.php"><?php echo $row['post_date']; ?></a> 

或者更短的變體:

<a href="edit.php"><?= $row['post_date']; ?></a> 
+1

很好的回答。不要忘記分號。 – ale8oneboy

+0

@ ale8oneboy謝謝,我完全忘了:) –

+0

謝謝。但我試過你的代碼,但它不起作用。你能檢查我在哪裏做錯了嗎 '​​'。$ row ['first_name']。''。$ row ['last_name']。'
'。 。'' –