使用PHP切换面板
不知是否有人能帮助我 从我找到的一些演示和教程中,我将页面组合起来,使用mySQL数据库中的值填充字段,将切换窗格添加到页面中 我遇到的问题是,在每一层上,只显示多条记录中的第一条 e、 g.屏幕当前显示2012年3月16日为唯一记录,2012年2月23日应有另一条记录 然后在2012年3月16日,下一个级别应该显示两个项目,而它只显示一个项目 我已经为此工作了一段时间,但我似乎找不到如何显示正确数量记录的解决方案 我只是想知道是否有人可以看看这个,请让我知道我错在哪里 我在下面添加了完整的脚本以供参考使用PHP切换面板,php,javascript,jquery,mysql,Php,Javascript,Jquery,Mysql,不知是否有人能帮助我 从我找到的一些演示和教程中,我将页面组合起来,使用mySQL数据库中的值填充字段,将切换窗格添加到页面中 我遇到的问题是,在每一层上,只显示多条记录中的第一条 e、 g.屏幕当前显示2012年3月16日为唯一记录,2012年2月23日应有另一条记录 然后在2012年3月16日,下一个级别应该显示两个项目,而它只显示一个项目 我已经为此工作了一段时间,但我似乎找不到如何显示正确数量记录的解决方案 我只是想知道是否有人可以看看这个,请让我知道我错在哪里 我在下面添加了完整的脚本
<!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>
面板测试
jQuery(文档).ready(函数(){
jQuery(“.content”).hide();
//使用类msg_body切换组件网
jQuery(“.heading”)。单击(函数()
{
jQuery(this).next(“.content”).slideToggle(500);
});
});
身体{
保证金:20px自动;
字体:12px Verdana,Arial,Helvetica,无衬线;
}
.第1层{
保证金:0;
填充:0;
宽度:500px;
}
.标题{
保证金:1px;
颜色:#fff;
填充:3x10px;
光标:指针;
位置:相对位置;
背景色:#c30;
}
.内容{
填充物:5px10px;
背景色:#fafafa;
}
p{padding:5px0;}
您正在获取所有记录,但只使用最后一条记录。
你应该这样说:
<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>
所以它看起来是这样的:
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>';
}
while($row=mysql\u fetch\u array($result))
{
$dateoftrip=$row['dateoftrip'];
$findname=$row['findname'];
回声'
';
}
您需要将输出放入循环中。此外,您可能需要修改javascript以考虑多个内容ID
您还应该将表单控件制作成数组,以便在需要时能够解析它们(请参见下文)
例如,这就是如何修改表单
?>
<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>
?>
在您的while循环中,您只需一遍又一遍地分配$dateoftrip和$findname。您好,这太棒了,非常感谢您。然而,我可能没有充分解释我自己,我真诚的道歉。如果有多个“第2层(内容)”记录,我希望将它们保存在同一个“第1层(日期)”记录下。因此,对于2012年3月16日,我希望“2012年3月16日”图层出现一次,两个“第2层内容条目”依次出现。你能告诉我怎么做吗。再次为没有正确解释这一点表示歉意。你能举个例子吗?(即使只使用html代码?)您好@Ofir,非常感谢您在这方面的持续帮助。这是该页面的链接。我希望这将有帮助,如果没有请让我知道,我将非常乐意提供它在一些其他方式。这让事情变得更复杂了。尝试在mysql查询中使用“groupby”函数。嗨,我试过了,但不幸的是它不起作用,但你给了我一个很好的开始。非常感谢。
?>
<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>