Php 使用mysql和pgp的jquery选项卡
我试图制作包含学生信息的选项卡,这些信息存储在数据库中。我希望第一个选项卡显示所有学生的信息。第二个选项卡显示其年级为A的学生的信息,第三个选项卡显示其年级为B的学生的信息 我编写了这段代码,但是只有第一个选项卡显示了学生的信息,但是第二个和第三个选项卡没有显示任何内容 代码有什么问题Php 使用mysql和pgp的jquery选项卡,php,jquery,mysql,tabs,Php,Jquery,Mysql,Tabs,我试图制作包含学生信息的选项卡,这些信息存储在数据库中。我希望第一个选项卡显示所有学生的信息。第二个选项卡显示其年级为A的学生的信息,第三个选项卡显示其年级为B的学生的信息 我编写了这段代码,但是只有第一个选项卡显示了学生的信息,但是第二个和第三个选项卡没有显示任何内容 代码有什么问题 <html> <head> <title>students table</title> <link rel="stylesheet" href="http:
<html>
<head>
<title>students table</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tabs-1">1</a></li>
<li><a href="#tabs-2">2</a></li>
<li><a href="#tabs-3">3</a></li>
</ul>
<?php
$connection = mysql_connect("","","");
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $connection);
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
?>
<div id="tabs-1">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
<?Php
$result2 = mysql_query("SELECT * FROM studentTable WHERE grade = 'A'");
while($row = mysql_fetch_array($result2))
{
?>
<div id="tabs-2">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
<?php
$result3 = mysql_query("SELECT * FROM studentTable WHERE grade = 'B'");
while($row = mysql_fetch_array($result3))
{
?>
<div id="tabs-3">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
</div>
</body>
</html>
学生桌
$(函数(){
$(“#制表符”).tabs();
});
在脚本中,您试图使用Jquery的tab方法
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
$(函数(){
$(“#制表符”).tabs();
});
这是在HTML中查找
<div id='tabs'>
You're tabs in here
</div>
你在这里
假设您的SQL语句没有返回“NULL”,那么我会说您的问题是您将自己命名为div的tab-1、tab-2、tab-3。有身份证的。这意味着Jquery找不到任何可以转换为tab的内容
将jquery调用更改为类似以下内容
<script>
$(function() {
$( ".tabsclass" ).tabs();
});
</script>
$(函数(){
$(“.tabsclass”).tabs();
});
而不是使用id的use类
<div class='tabsclass' id='tab-1'>
You're tabs in here
</div>
<div class='tabsclass' id='tab-2'>
You're tabs in here
</div>
<div class='tabsclass' id='tab-3'>
You're tabs in here
</div>
你在这里
你在这里
你在这里
我认为你的问题是因为你在while()
循环中有选项卡-
打开标签
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
?>
<div id="tabs-1"> //this here needs to be above/outside while($row = mysql_fetch_array($result)){
还有,echo'
位于每个选项卡div的末尾。如果您实际上没有表,则可能希望删除这些选项卡。使用mysqli而不是mysql作为其过时且不再受mysqli支持的对象。为每个选项卡使用不同的行变量名,如row1 row2 etc OP具有绑定选项卡的正确html-代码>
<div id="tabs-1">
<?php
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
...
}
?>
</div>
<div id="tabs-2">
<?php
$result2 = mysql_query("SELECT * FROM studentTable WHERE grade = 'A'");
while($row = mysql_fetch_array($result2))
{
...
}
?>
</div>
<div id="tabs-3">
<?php
$result3 = mysql_query("SELECT * FROM studentTable WHERE grade = 'B'");
while($row = mysql_fetch_array($result3))
{
...
}
?>
</div>