读书人

php查询数据库表有关问题

发布时间: 2013-07-01 12:33:04 作者: rapoo

php查询数据库表问题

<!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=gb2312" />
<title>学生课题查询</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 14px}
-->
</style>
</head>

<body>
<?php
//######################学生查询所选课题##########################
include "config.php";
include "header.php";?>
<?
if($search)
{
if ($xuehao=="")
{
echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>请填写您的学号!</big></b></font></p>";
echo "<meta http-equiv=\"refresh\" content=\"1;url=query.php\">";
exit;
}

$query="select * from $student_table where xuehao='$xuehao'";
mysql_query("set names 'gb2312'");
$result=mysql_query($query);
$row=mysql_fetch_array($result);
if($row==0)
{
echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你还没有注册,或者你的输入有误,请重新输入!</big></b></font></p>";
echo "<meta http-equiv=\"refresh\" content=\"2;url=query.php\">";
exit;
}

$query="select id as sm from $student_table where xuehao='$xuehao'";
mysql_query("set names 'gb2312'");
$result=mysql_query($query);
$row=mysql_fetch_array($result);
if($row[sm]==0)
{
echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你还没有选择课题,请去选题!</big></b></font></p>";
echo "<meta http-equiv=\"refresh\" content=\"2;url=keti_list.php\">";
exit;
}
?>
<table width="700" border="0" cellspacing="1" cellpadding="0" bgcolor="#333333" align="center">
<tr>
<td width="78" height="30" bgcolor="#FFFFFF">
<div align="center" class="text">
<p class="STYLE1">学生学号</p>
</div>
</td>
<td width=97 height="30" bgcolor="#FFFFFF">
<div align="center" class="STYLE1">学生姓名</div>
</td>
<td width="329" height="30" bgcolor="#FFFFFF">
<div align="center" class="STYLE1"> 课题名称 </div> </td>
<td width=106 height="30" bgcolor="#FFFFFF">
<div align="center" class="STYLE1">指导教师</div>
</td>
<td width=84 height="30" bgcolor="#FFFFFF">
<div align="center" class="STYLE1">职称</div> </td>
</tr>
<?
$n=0;
$query=mysql_query("select * from $jiaoshi_table,$student_table where $jiaoshi_table.id=$student_table.id and $student_table.xuehao='$xuehao'");


mysql_query("set names 'gb2312'");
while($row=mysql_fetch_array($query)){
if(($n%2)!='0'){
echo "<tr bgcolor=#FFFFff>";}
else{
echo "<tr bgcolor=#E4E4E4>";
}
echo"
<td height='22' class='STYLE1'> <div align='center'>".$row['xuehao']."</div></td>
<td height='22'>
<div align='center' class='STYLE1'>".$row['name']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$row['subject']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$row['teacher']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$row['zhicheng']."</div></td>
</tr> ";
$n++;
}
?></table>
<p>
</p>
<?php include "foot.php";?>


当我输入学号查询的时候,运行结果却是一堆乱七八糟的东西。。。
注:我的表名叫做teacher,student PHP MySQL 数据库
[解决办法]
你没开启段标签
<?if($search){ if ($xuehao=="") {
改成<?php if($search){ if ($xuehao=="") {

[解决办法]
if($search)
{

这个if没有关闭,即少了 } 号
[解决办法]
…… 楼主这错误看着太头晕,建议你用eclipse什么的去检查一下,丢的东西有点多啊

读书人网 >PHP

热点推荐