我正在尝试使用一个函数在我的php数组中显示附加信息。我正在回显显示我的类的信息的表,并且我无法在PHP内部使Jquery工作。我不是Jquery或PHP中最有经验的人,所以我必须把它完全错误。
编辑:我知道我的PHP查询不安全,我最终开始转换它们。 这是我的代码<link rel="stylesheet" type="text/css" href="css/bigcalendar.css">
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Webbook | View Schedule</title>
<link rel='stylesheet' type='text/css' href='css/style.css' />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script type='text/javascript' src='js/jquery.ba-hashchange.min.js'></script>
<script type='text/javascript' src='js/dynamicpage.js'></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#hidetest").toggle(1000);
});
});
</script>
</head>
<body>
<div id="page-wrap">
<header>
<?php include "navbar.php";?>
</header>
<section id="main-content">
<div id="guts">
<h2>View Schedule</h2>
<?php
//get database settings
include("dbinfo.php");
?>
<div align="center">
<?php
$sqlschedule = mysql_query("SELECT * FROM schedule WHERE student='Austin' ORDER BY `hour` ASC");
$num_rows = mysql_num_rows($sqlschedule);
//Table starting tag and header cells
while($row = mysql_fetch_array($sqlschedule)){
//Display the results in different cells
$hour = $row['hour'];
$class = $row['class'];
$teacher = $row['teacher'];
$classid = $row['classid'];
$sqlclassid = mysql_query("SELECT * FROM classes WHERE classid=$classid");
while($row2 = mysql_fetch_array($sqlclassid)){
$hour2 = $row2['hour'];
$class2 = $row2['class'];
$teacher2 = $row2['teacher'];
}
if($class == ""){
$class = $class2;
}
if($teacher == ""){
$teacher = $teacher2;
}
$sqlhourinfo = mysql_query("SELECT * FROM hours WHERE hour='$hour'");
while($row3 = mysql_fetch_array($sqlhourinfo)){
$starttime = strftime("%l:%M %P", strtotime($row3['starttime']));
$endtime = strftime("%l:%M %P", strtotime($row3['endtime']));
}
/*
$from = mysql_query("SELECT * from members WHERE username='$fromuser'");
$num_rows = mysql_num_rows($from);
//Table starting tag and header cells
while($row = mysql_fetch_array($from)){
//Display the results in different cells
$otherid = $row['id'];
$theusername = $row['username'];
}
*/
echo '<p>This is a paragraph with little content.</p>
<p style="display:none" id="hidetest">This is another small paragraph.</p>
<button>Toggle</button>
';
echo '
<table id="background-image" width="50%" border="0" cellspacing="5" cellpadding="10">
<tr>
<th width="10%" rowspan="2" class="scheduleform" scope="col">'.$hour.'</th>
<td align="left" scope="col">'.$class.'</td>
</tr>
<tr>
<td align="left">'.$teacher.'</td>
</tr>
<tr>
<td colspan="2"><p>Starts: '.$starttime.'<br>
Ends: '.$endtime.'
</p></td>
</tr>
<tr>
<td>
<a href="#" id="opener">
<img border="0" src="/webbook/images/256.png" alt="Add Assignment" width="32" height="32"></a>
</td>
<td>
<a href="#">
<img border="0" src="/webbook/images/256 (1).png" alt="Edit Assignment" width="32" height="32"></a>
</td>
</tr>
</table>
</p>
';
}
?>
</div>
</div>
</div>
</div>
</section>
</div>
<footer>
©2013 iHeff Webbook
</footer>
<?php /*
include('../footer.php');
*/ ?>
</body>
</html>
所以我想要实现的是有一个图像的链接,上面写着“添加作业”。我想能够点击它,然后显示一个隐藏的表单,你可以切换它。先感谢您。
答案 0 :(得分:0)
您的链接ID是“开启者”,但您使用的是('button').click(
...等。
使用$('#opener').click
代替。这应该将点击功能绑定到链接。
答案 1 :(得分:0)
您只需将display:none
设置为表单容器并注册一个单击侦听器并使用jquery .show()弹出表单即可。这是一个例子:
<a href="#" id="addassgn">Add Assignment</a>
<div id="assgnform" style="display:none">
<h1>Assignment Form</h1>
Name: <input type="text"/><br/>
Class: <input type="text"/><br/>
File: <input type="text"/><br/>
<input type="submit"/>
</div>
$('#addassgn').click(function() {
$('#assgnform').show();
});