Home >Backend Development >PHP Tutorial >php读取数据库中表问题

php读取数据库中表问题

WBOY
WBOYOriginal
2016-06-23 14:09:521127browse

运行结果如下图,貌似只有前24行有问题。如果读取数据库表正常,每一栏里应该显示数据库当中的内容。

<?php//######################课题详细信息##########################  include "config.php";  include "header.php";?><title>课题详细信息</title><style type="text/css"><!--.STYLE1 {	font-size: 16px;	color: #FF0000;}.STYLE2 {font-size: 14px}.STYLE3 {font-size: 12px}--></style><p></p><?php        $query="select * from $jiaoshi_table where id='".$id."'";		mysql_query("set names 'GB2312'");		$result=mysql_query($query);		$row=mysql_fetch_array($result);?><table width="700" border="1" align="center" cellpadding="0" cellspacing="1"  class="text">  <!--DWLayoutTable-->  <form name="form1" method="post" action="xiangxiziliao.php">    <tr bgcolor="#E4E4E4">       <td height="27" colspan="3"><span class="STYLE1 STYLE2">>>>课题信息</span></td>    </tr>	<tr>       <td width="184" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right">课题编号:</div>      </div></td>      <td width="507" bgcolor="#FFFFFF" height="39"> <input type="text" name="id" size="28" value="<?php echo $row['id'] ?>"  readonly="readonly">      </td>    </tr>    <tr>       <td width="184" bgcolor="#E4E4E4"><div align="center" class="STYLE2">        <div align="right">课题名称:</div>      </div></td>      <td width="507" bgcolor="#E4E4E4" height="39"> <input type="text" name="subject1" size="45" value="<?php echo $row['subject'] ?>" readonly="readonly">      </td>    </tr>	<tr>       <td width="184" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right">指导教师姓名:</div>      </div></td>      <td width="507" bgcolor="#FFFFFF" height="36"> <input type="text" name="teacher1" size="30" value="<?php echo $row['teacher'] ?>" readonly="readonly">      </td>    </tr>	<tr>       <td width="184" bgcolor="#E4E4E4"><div align="center" class="STYLE2">        <div align="right">指导教师职称:</div>      </div></td>      <td width="507" bgcolor="#E4E4E4" height="41"> <input type="text" name="zhicheng1" size="25" value="<?php echo $row['zhicheng'] ?>" readonly="readonly">      </td>    </tr>	<tr>       <td width="184" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right">教师的研究方向:</div>      </div></td>      <td width="507" bgcolor="#FFFFFF" height="41"> <input type="text" name="specialized1" size="25" value="<?php echo $row['specialized'] ?>" readonly="readonly">      </td>    </tr>	<tr>       <td width="184" bgcolor="#E4E4E4"><div align="center" class="STYLE2">        <div align="right">课题专业代码:</div>      </div></td>      <td width="507" bgcolor="#E4E4E4" height="41"> <input type="text" name="code1" size="20" value="<?php echo $row['code'] ?>" readonly="readonly">      <span class="STYLE3"></span></td>    </tr>	<tr>       <td width="184" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right">课题所需学生人数:</div>      </div></td>      <td width="507" bgcolor="#FFFFFF" height="41"> <input type="text" name="number1" size="20" value="<?php echo $row['number'] ?>" readonly="readonly">      <span class="STYLE3"></span></td>    </tr>	<tr>       <td width="184" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right">课题简要说明:</div>      </div></td>      <td width="507" bgcolor="#FFFFFF" height="163"><label>        <textarea name="introduction" cols="60" rows="10" readonly="readonly"><?php echo $row['beizhu'] ?></textarea>      </label></td>    </tr>  </form></table><p></p><?php include "foot.php"?>


回复讨论(解决方案)

 $query="select * from $jiaoshi_table where id='".$id."'";
修改为:
 $query="select * from $jiaoshi_table where id='$id'";

 $query="select * from $jiaoshi_table where id='".$id."'";
修改为:
 $query="select * from $jiaoshi_table where id='$id'"; 我刚刚照你的方法试了,还是不行啊

你的 $id 在哪里赋值的?
总不会在 config.php 或 header.php 里吧?

同楼上大神,还有难道是我记错了,$jiaoshi_table不用引号的么?

你的 $id 在哪里赋值的?
总不会在 config.php 或 header.php 里吧?

<?php  $n=0;   $query=mysql_query("select count(*) as sm from jiaoshi");  mysql_query("set names 'GB2312'");   $row=mysql_fetch_array($query);    $count=$row['sm'];    if(empty($offset))              {$offset=0;}	echo  $offset;   $query=mysql_query("select * from jiaoshi order by teacher asc limit $offset,$list_num") or die ("fail");   mysql_query("set names 'GB2312'");   while($row=mysql_fetch_array($query)){        if(($n%2)!='0'){ 	  echo "<tr bgcolor=#FFFFff>";}	  else{	  echo "<tr bgcolor=#E4E4E4>";	  }	if($row['surplus']==0)	     $ss="不可选";	else $ss="可选";      echo"	 <td   height='22' class='STYLE1'> <div align='center'>".$row['id']."</div></td>	 <td   height='22'> 		<div align='center' class='STYLE1'>".$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>    <td  height='22' class='STYLE1'> <div align='center'>".$row['number']."</div></td>	<td   height='22' class='STYLE1'> <div align='center'>".$row['xuehao']."</div></td>	<td   height='22' class='STYLE1'> <div align='center'>".$ss."</div></td>	<td   height='22' class='STYLE1'><div align='center'>		<a href=xiangxiziliao.php?id=".$row['id'].">查看</a></div></td>  </tr> ";   $n++;   } ?>
最下边那一行应该就是吧?

LZ你是想通过URL把ID传进来?

那应该用$_GET方法来实现

LZ你是想通过URL把ID传进来?

那应该用$_GET方法来实现 谢谢~能告诉我具体语句吗?因为我还是个新手

你是指 查看

那么 get 方式的 id 要用 $_GET['id'] 访问,而你却直接 $id 了,那怎么行呢?
至少需要有 $id = $_GET['id']; 才可以

你的URL点击进来的时候应该是这样子吧?
xiangxiziliao.php?id=1

然后

if(isset($_GET['id'])&&$_GET['id']!=''){
  echo $_GET['id'];
}

测试下

更详细的参考w3school吧

你是指 查看

那么 get 方式的 id 要用 $_GET['id'] 访问,而你却直接 $id 了,那怎么行呢?
至少需要有 $id = $_GET['id']; 才可以 那具体应该如何改呢?

<?php   $id = $_GET['id'];        $query="select * from $jiaoshi_table where id='".$id."'";        mysql_query("set names 'GB2312'");        $result=mysql_query($query);....

<?php   $id = $_GET['id'];        $query="select * from $jiaoshi_table where id='".$id."'";        mysql_query("set names 'GB2312'");        $result=mysql_query($query);....
正常显示了,一如既往地感谢!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php查询数据库表问题Next article:配置?服务器?