0

我正在尝试使用一个函数在我的 php 数组中显示附加信息。我正在回显显示我的类信息的表,我无法让 Jquery 在 PHP 中工作。我在 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>
      &copy;2013 iHeff Webbook
    </footer>
    <?php   /* 
include('../footer.php'); 
*/ ?>
</body>

</html>

所以我想要实现的是有一个带有“添加分配”的图像的链接。我希望能够单击它,然后显示一个隐藏的表单,您可以切换它。先感谢您。

4

2 回答 2

0

您的链接的 id 是“opener”,但您正在使用('button').click(...等。

改为使用$('#opener').click。这应该将点击功能与链接联系起来。

于 2013-02-21T21:34:49.290 回答
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();
});

http://jsfiddle.net/vZreC/

于 2013-02-21T21:37:17.447 回答