2017-06-20 12 views
-2

我在學校項目上工作時遇到了麻煩,而且我被卡住了。 我正在製作一個網站,您可以輕鬆搜索遊樂園。如何在PHP中提供href的表格

我用PHP做了一個while循環,並把數據庫中的信息放到我循環的表中。我已經將所有信息放在TD中,並且我想創建一個-HREF,因此當我點擊第一個公園之一時,它將重定向到一個示例:example.php?park = 1爲第二個公園示例:示例。 PHP?公園= 2。

這裏是同時:

<div class="pretpark-container"> 
    <table id="pretpark-table"> 
     <?php while($pretpark = mysqli_fetch_array($result)){ 
     echo "<tr>"; 
     if(file_exists(__DIR__ . '/img/'. $pretpark['ParkImage'])): ?> 
     <td><img height="125px;" width="200px;"" src="/WikiParksWeb/Wikiparks-Website/img/<?php print($pretpark['ParkImage']); ?>"></td> 
     <?php else: ?> 
     <?php endif; 
     echo "<td>".$pretpark['ParkName']."</td>"; 
     echo "<td>".$pretpark['ParkLocation']."</td>"; 
     echo "<td>".$pretpark['ParkOpeninsTime']."</td>"; 
     echo "<td>".$pretpark['ParkPrices']."</td>"; 
     echo "<td>".$pretpark['ParkShortDescription']."</td>"; 
     echo "</tr>"; 
     ?> 
     <tr class="filler"></tr> 
     <?php 
     } 
     ?>  
    </table>  
    </div> 

每個遊樂場都有一個ID,它的DB表稱爲ParkId。 有人可以幫我,我必須把href。和我如何能做到像它這樣的例子:使用example.php公園= ParkId

我希望一切是可以理解我剛纔說的:/

感謝,

回答

0

你可以這樣做:

<div class="pretpark-container"> 
    <table id="pretpark-table"> 
     <?php while($pretpark = mysqli_fetch_array($result)){ 
     echo "<tr>"; 
     if(file_exists(__DIR__ . '/img/'. $pretpark['ParkImage'])): ?> 
     <td><img height="125px;" width="200px;"" src="/WikiParksWeb/Wikiparks-Website/img/<?php print($pretpark['ParkImage']); ?>"></td> 
     <?php else: ?> 
     <?php endif; 
     echo "<td>".$pretpark['ParkName']."</td>"; 
     echo "<td>".$pretpark['ParkLocation']."</td>"; 
     echo "<td>".$pretpark['ParkOpeninsTime']."</td>"; 
     echo "<td>".$pretpark['ParkPrices']."</td>"; 
     echo "<td>".$pretpark['ParkShortDescription']."</td>"; 
     echo "<td><a href='example.php?park=".$pretpark['Parkid']."'> More Details</a></td>"; 
     echo "</tr>"; 
     ?> 
     <tr class="filler"></tr> 
     <?php 
     } 
     ?>  
    </table>  
    </div> 
0
<div class="pretpark-container"> 
    <table id="pretpark-table"> 
     <?php while($pretpark = mysqli_fetch_array($result)){ 
     echo "<tr>"; 
     if(file_exists(__DIR__ . '/img/'. $pretpark['ParkImage'])): ?> 
     <td><img height="125px;" width="200px;"" src="/WikiParksWeb/Wikiparks-Website/img/<?php print($pretpark['ParkImage']); ?>"></td> 
     <?php else: ?> 
     <?php endif; 
     echo "<td>".$pretpark['ParkName']."</td>"; 
     echo "<td>".$pretpark['ParkLocation']."</td>"; 
     echo "<td>".$pretpark['ParkOpeninsTime']."</td>"; 
     echo "<td>".$pretpark['ParkPrices']."</td>"; 
     echo "<td>".$pretpark['ParkShortDescription']."</td>"; 
     **echo "<td><a href='detailpage.php?id=".$pretpark['ParkId']."'></td>";** 
     echo "</tr>"; 
     ?> 
     <tr class="filler"></tr> 
     <?php 
     } 
     ?>  
    </table>  
    </div> 

我已經加入一行粗體格式。你可以從中得到線索。

+0

格式不傳遞給代碼塊。 – chris85

0

的替代線路

echo "<td>".$pretpark['ParkName']."</td>"; 

它會是這樣的..

echo "<td><a href=\"example.php?id=".$pretpark['ParkId']."\">".$pretpark['ParkName']."</a></td>"; 
需要

反斜槓轉義引號如此他們出來在HTML中,而不是解釋由php