简体   繁体   English

使用PHP切换面板

[英]Toggle Panels With PHP

I wonder whether someone may be able to help me please. 我想知道是否有人可以帮助我。

From some demos and tutorials I've found, I've put together this page which adds toggle panes to a page using values from a mySQL database to populate the fields. 从我发现的一些演示和教程中,我整理了页面,该页面使用mySQL数据库中的值填充字段,将切换窗格添加到页面。

The problem I'm having is that at each layer only the first out of multiple records is shown. 我遇到的问题是,在每一层中,仅显示多个记录中的第一个。

eg The screen currently shows 16/03/2012 as the only record, there should be one other record for the 23/02/2012. 例如,屏幕当前显示16/03/2012为唯一记录,2012年2月23日应该还有其他记录。

Then within the 16/03/2012, the next level should show two items, whereas it is only showing one. 然后在16/03/2012中,下一个级别应显示两个项目,而仅显示一个项目。

I've been working on this for a while now but I can't seem to find the solution of how to show the correct number of records. 我已经为此工作了一段时间,但似乎找不到如何显示正确数量的记录的解决方案。

I just wondered whether someone could perhaps have a look at this please and let me know where I'm going wrong. 我只是想知道是否有人可以看看这个,然后让我知道我要去哪里了。

I've added the full script below for reference. 我在下面添加了完整的脚本以供参考。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Panel Test</title> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
<script type="text/javascript"> 
jQuery(document).ready(function() {
  jQuery(".content").hide();
  //toggle the componenet with class msg_body
  jQuery(".heading").click(function()
  {
    jQuery(this).next(".content").slideToggle(500);
  });
});
</script>
<style type="text/css"> 
body {
    margin: 20px auto;
    font: 12px Verdana,Arial, Helvetica, sans-serif;
}
.layer1 {
margin: 0;
padding: 0;
width: 500px;
}

.heading {
margin: 1px;
color: #fff;
padding: 3px 10px;
cursor: pointer;
position: relative;
background-color:#c30;
}
.content {
padding: 5px 10px;
background-color:#fafafa;
}
p { padding: 5px 0; }
</style> 
</head> 
<?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 ORDER BY dateoftrip DESC");

if (mysql_num_rows($result) == 0) 
// table is empty 
  echo 'There are currently no finds recorded for this location.'; 
  else
 { 
    while ($row = mysql_fetch_array($result)) 
    { 
    $dateoftrip = $row['dateoftrip']; 
    $findname = $row['findname'];   
{ 
}
}
}
?>
<body>
<div class="layer1"> 
        <p class="heading"><input name="dateoftrip" id="dateoftrip" type="text" value="<?php echo $dateoftrip;?>" disabled="disabled"/></p> 
        <div class="content"> 
            <input name="findname" id="findname" type="text" value="<?php echo $findname;?>" disabled="disabled"/>
        </div> 
</div> 
</body> 
</html> 

Many thanks and kind regards 非常感谢和问候

You are fetching all the records but using only the last one. 您正在获取所有记录,但仅使用最后一个。 You should put this: 你应该这样:

<div class="layer1"> 
        <p class="heading"><input name="dateoftrip" id="dateoftrip" type="text" value="<?php echo $dateoftrip;?>" disabled="disabled"/></p> 
        <div class="content"> 
            <input name="findname" id="findname" type="text" value="<?php echo $findname;?>" disabled="disabled"/>
        </div> 
</div> 

in the while loop which fetch the data: 在获取数据的while循环中:

    while ($row = mysql_fetch_array($result)) 
    { 
     $dateoftrip = $row['dateoftrip']; 
    $findname = $row['findname'];

So it will look like this: 所以它看起来像这样:

        while ($row = mysql_fetch_array($result)) 
        { 
         $dateoftrip = $row['dateoftrip']; 
        $findname = $row['findname'];
echo '<div class="layer1"> 
            <p class="heading"><input name="dateoftrip" id="dateoftrip" type="text" value="'.$dateoftrip.'" disabled="disabled"/></p> 
            <div class="content"> 
                <input name="findname" id="findname" type="text" value="'.$findname.'" disabled="disabled"/>
            </div> 
    </div>';
       }

You need to put your output inside your loop. 您需要将输出放入循环中。 Also you may have to modify your javascript to account for the multiple content ids. 另外,您可能需要修改JavaScript以解决多个内容ID。

You should also make the form controls into arrays so you'll be able to parse them if needed (see below). 您还应该将表单控件分成数组,以便在需要时能够解析它们(请参见下文)。

For example, this is how to modify the form. 例如,这是修改表单的方法。

?>
<body>
<div class="layer1"> 
<?php
   while ($row = mysql_fetch_array($result)) 
    { 
    $dateoftrip = $row['dateoftrip']; 
    $findname = $row['findname'];   

    $i++;
?>
    <p class="heading"><input name="dateoftrip[]" id="dateoftrip" type="text" value="<?php echo $dateoftrip;?>" disabled="disabled"/></p> 
    <div class="content"> 
        <input name="findname[]" id="findname" type="text" value="<?php echo $findname;?>" disabled="disabled"/>

<?php

{ 
}
}
}    
?>
    </div> 
</div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM