2012-02-28 78 views
0

我想知道是否有人能夠幫助我。在單選按鈕上創建表格單擊

我把下面的代碼放在一起,它創建了與登錄用戶相關的日期和相關單選按鈕列表。

<?php 
mysql_connect("hostname", "username", "password")or 
die(mysql_error()); 
mysql_select_db("database"); 


$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.userid, finds.locationid, detectinglocations.locationid, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 GROUP By dateoftrip ORDER BY dateoftrip DESC"); 

if (mysql_num_rows($result) == 0) 
// table is empty 
    echo 'There are currently no finds recorded for this location.'; 
    else 
{ 
    echo"<table>\n"; 
    while (list($userid, $dateoftrip, $findname) = 
    mysql_fetch_row($result)) 
    { 

    echo"<tr>\n" 
    . 
    "<td><input type='radio' name='show' dateoftrip value='{$dateoftrip}' /></td>\n" 
    ."<td><small>{$dateoftrip}</small><td>\n" 
    ."</tr>\n"; 
    } 
    echo'</table>'; 
} 

?> 
<form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data" class="style10"> 

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{ 
    if (isset($_POST['show'])) 
     $dateoftrip = intval($_POST['show']); 

    echo"<table>\n"; 
    while (list($dateoftrip, $findname) = 
    mysql_fetch_row($result)) 
    { 

    echo"<tr>\n" 

    ."<td><small>{$findname}</small><td>\n" 
    ."</tr>\n"; 
    } 
    echo'</table>'; 
} 

     ?> 
<input type="hidden" name="action" id="action" /> 
</form> 

我想什麼是能夠做到的,這我有困難,是在單選按鈕被選中,我想另一個表在屏幕上渲染的「findnames」應用列表到選定的日期。

我已經設法讓第一部分工作,但在單選按鈕被選中時,沒有任何反應。

我在這方面花了相當多的時間,但我似乎無法找到答案。

我只是想知道是否有人可以看看這個請讓我知道我哪裏出了問題。

非常感謝

修正代碼

<?php 
mysql_connect("hostname", "username", "passowrd")or 
die(mysql_error()); 
mysql_select_db("database"); 


$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.userid, finds.locationid, detectinglocations.locationid, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 GROUP By dateoftrip ORDER BY dateoftrip DESC"); 

if (mysql_num_rows($result) == 0) 
// table is empty 
    echo 'There are currently no finds recorded for this location.'; 
    else 
{ 
    echo"<table>\n"; 
    while (list($userid, $dateoftrip, $findname) = 
    mysql_fetch_row($result)) 
    { 

    echo"<tr>\n" 
    . 
    "<td><input type='radio' name='show' onclick dateoftrip value='{$dateoftrip}' /></td>\n" 
    ."<td><small>{$dateoftrip}</small><td>\n" 
    ."</tr>\n"; 
    } 
    echo'</table>'; 
} 
?> 

<table width="300" border="1"> 
<tr id="findname"><th>Findname</th></tr> 

</table> 
<script type="text/javascript">  
function displayRow(){   
var row = document.getElementById("findname"); 
if (row.style.display == '') 
row.style.display = 'none'; else row.style.display = '';  
} 
</script> 
+0

使用ajax() – 2012-02-28 13:38:57

回答

0

要做到這一點,你需要JQuery的或JavaScript。 .load() is the easiest to do它會將頁面或div從頁面加載到頁面上已經存在的div中。你可以這樣做.Click().change()

+0

嗨,非常感謝。我不得不承認在Javascript方面沒有特別的經驗,但是我已經把我認爲你的建議放在一起了。我不知道的唯一的事情是如何綁定正確的findname或名稱,如果有多個。我修改了我原來的帖子,以反映代碼的變化。你可能看看這個,並提供一些關於如何鏈接按鈕和正確的細節的指導。非常感謝 – IRHM 2012-02-28 14:48:48