【问题标题】:Create Table On Radio Button Click在单选按钮单击时创建表
【发布时间】:2012-02-28 22:49:56
【问题描述】:

我想知道是否有人可以帮助我。

我将下面的代码放在一起,它创建了一个日期列表和与登录用户相关的相关单选按钮。

<?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>

我希望能够做的,我遇到困难的是,在选择单选按钮时,我希望在屏幕上呈现另一个表格,其中包含适用于所选日期的“查找名称”列表.

我已经设法让第一部分工作,但是在选择单选按钮后,什么都没有发生。

我在这方面花了很多时间,但我似乎找不到答案。

我只是想知道是否有人可以看看这个,让我知道我哪里出错了。

非常感谢

修改后的代码

<?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>

【问题讨论】:

    标签: php html


    【解决方案1】:

    为此,您需要 JQuery 或 javascript。 .load() is the easiest to do 它将页面或页面中的 div 加载到页面上已经存在的 div 中。你可以这样做.Click().change()

    【讨论】:

    • 嗨,非常感谢。我不得不承认我在 Javascript 方面并不是特别有经验,但是,我已经尝试过将我认为您的建议放在一起。我唯一不确定的是如何绑定正确的 findname 或名称,如果有多个的话。我已经修改了我的原始帖子以反映代码的变化。您能否看一下这个并就如何链接按钮和正确的详细信息提供一些指导。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 2012-09-06
    • 2016-12-04
    • 2011-03-05
    相关资源
    最近更新 更多