2016-08-26 16 views
0

我有問題。我有一個數據庫,我想把她的價值觀和他們顯示在一個HTML表格。我已經創建了數據庫和她的表格,並使用jQuery隱藏並使用下拉列表中的一個按鈕顯示它。問題是,當我點擊按鈕時,我想顯示這個表格,而其他所有時間我都希望它被隱藏。出於這個原因,我有顯示:無;在CSS上。但是當我這樣做時,我只能看到數據庫的第一行。我刪除顯示:無;我可以看到所有的行,但在我的頁面上永久顯示。我錯在哪裏?我怎樣才能隱藏一個表與CSS和jQuery的,它有一個數據庫值?

jQuery的

<script> 
$(document).ready(function(){ 
$('#p4').click(function(){ //p4 id για το κουμπί της dropdown λίστας 
$('#table4').show(); 
$('#table5').show(); 
    }); 
}); 
</script> 

PHP

<table name="table4" id="table4" width="941" border="1" cellspacing="0" cellpadding="3" align="center"> 
<tr> 
<td width="8%"><b>No.</b></td> 
<td width="8%"><b>Όνομα</b></td> 
<td width="11%"><b>Επώνυμο</b></td> 
<td width="11%"><b>Πατρώνυμο</b></td> 
<td width="9%"><b>Διεύθυνση Κατοικίας</b></td> 
<td width="6%"><b>Πόλη</b></td> 
<td width="7%"><b>ΤΚ</b></td> 
<td width="7%"><b>ΑΜΚΑ</b></td> 
<td width="7%"><b>Τηλέφωνο</b></td> 
<td width="7%"><b>E-mail</b></td> 
</tr> 
</table> 
<?php 
// Run the actual connection here 
$link=mysqli_connect("$dbhost","$dbusername","$dbpass") or die ("could not connect to mysql"); 
mysqli_select_db($link,"$dbname") or die ("no database");   
$result = mysqli_query($link, "SELECT * FROM lista_asthenwn"); 
$astheneis = mysqli_num_rows($result); 
while($row = mysqli_fetch_array($result)){ 
?> 
<table name="table5" id="table5" class="table5" width="941" border="1" cellspacing="0" cellpadding="3" align="center"> 
<tr> 
<td width="13%"><?php echo $row['id']?></td> 
<td width="13%"><?php echo $row['Onoma']?></td> 
<td width="9%"><?php echo $row['Epwnumo']?></td> 
<td width="6%"><?php echo $row['Patrwnumo']?></td> 
<td width="21%"><?php echo $row['Dieuthunsh']?></td> 
<td width="10%"><?php echo $row['Poli']?></td> 
<td width="9%"><?php echo $row['TK']?></td> 
<td width="10%"><?php echo $row['AMKA']?></td> 
<td width="8%"><?php echo $row['Til']?></td> 
<td width="3%"><?php echo $row['Email']?></td> 
</tr> 
</table> 
<?php 
// close while loop 
} 
// close connection 
mysqli_close($link); 
?> 

CSS

#table4 { 
margin-top: 150px; 
display:none; 
} 
#table5 { 
display:none; 
} 

回答

1

嘗試遍歷行,而不是表 - 不要在頭後關上table標籤,只有在整張桌子用完後關閉標籤。

您目前正在重複id(表5),它應該是唯一的! jQuery(正確)期望每個id只會在頁面中出現一次,並且僅當使用id選擇器時纔會返回第一個元素(https://api.jquery.com/id-selector/)。

<table name="table4" id="table4" width="941" border="1" cellspacing="0" cellpadding="3" align="center"> 
    <tr> 
    <td width="8%"><b>No.</b></td> 
    <td width="8%"><b>Όνομα</b></td> 
    <td width="11%"><b>Επώνυμο</b></td> 
    <td width="11%"><b>Πατρώνυμο</b></td> 
    <td width="9%"><b>Διεύθυνση Κατοικίας</b></td> 
    <td width="6%"><b>Πόλη</b></td> 
    <td width="7%"><b>ΤΚ</b></td> 
    <td width="7%"><b>ΑΜΚΑ</b></td> 
    <td width="7%"><b>Τηλέφωνο</b></td> 
    <td width="7%"><b>E-mail</b></td> 
    </tr> 

    <?php 
    // Run the actual connection here 
    $link=mysqli_connect("$dbhost","$dbusername","$dbpass") or die ("could not connect to mysql"); 
    mysqli_select_db($link,"$dbname") or die ("no database");   
    $result = mysqli_query($link, "SELECT * FROM lista_asthenwn"); 
    $astheneis = mysqli_num_rows($result); 
    while($row = mysqli_fetch_array($result)): 
    ?> 
    <tr> 
    <td width="13%"><?php echo $row['id']?></td> 
    <td width="13%"><?php echo $row['Onoma']?></td> 
    <td width="9%"><?php echo $row['Epwnumo']?></td> 
    <td width="6%"><?php echo $row['Patrwnumo']?></td> 
    <td width="21%"><?php echo $row['Dieuthunsh']?></td> 
    <td width="10%"><?php echo $row['Poli']?></td> 
    <td width="9%"><?php echo $row['TK']?></td> 
    <td width="10%"><?php echo $row['AMKA']?></td> 
    <td width="8%"><?php echo $row['Til']?></td> 
    <td width="3%"><?php echo $row['Email']?></td> 
    </tr> 
    <?php 
    // close while loop 
    endwhile; 

    // close connection 
    mysqli_close($link); 
    ?> 
</table> 

因爲要循環就這樣,我已經改變了while循環使用有角度的PHP作爲一種模板風格(:endwhile)。

+0

它適合我。非常感謝我的朋友! :) –

相關問題