php做一个分类查询
这是代码
<?php
$conn=mysql_connect("localhost","root","123456")or die('失败');
mysql_query("set names 'utf8'")or die('失败');
mysql_select_db("mstudent",$conn)or die('失败');
$keyword0=$_GET['keyword0'];
$keyword1=$_GET['keyword1'];
$keyword2=$_GET['keyword2'];
$keyword3=$_GET['keyword3'];
$keyword4=$_GET['keyword4'];
$sql="Select * from abc where 1";
if($keyword0)
{
    $sql.="and area={$keyword0}";
}
if($keyword1)
{
    $sql.="and kind={$keyword1}";
}
if($keyword2)
{
    $sql.="and sex={$keyword2}";
}
if($keyword3)
{
    $sql.="and age={$keyword3}";
}
if($keyword4)
{
    $sql.="and zhongxue={$keyword4}";
}
$res=mysql_query($sql) ;
$row=mysql_fetch_assoc($res) ;
$ress=mysql_query("Select * from abc WHERE  kind= {$keyword0}",$conn) ;
$rows=mysql_fetch_assoc($ress);
?>
<table border="1">
    <tr bgcolor="#eoeoeo">
        <th>考号</th>
        <th>姓名</th>
        <th>语文</th>
        <th>数学</th>
        <th>英语</th>
        <th>总分</th>
        <th>地区</th>
        <th>类别</th>
        <th>性别</th>
        <th>年龄</th>
        <th>中学</th>
    </tr>
    <tr>
        <td><?= $rows['number'] ?></td>
        <td><?= $rows['name'] ?></td>
        <td><?= $rows['chinese'] ?></td>
        <td><?= $rows['math'] ?></td>
        <td><?= $rows['english'] ?></td>
        <td><?= $rows['chinese'] + $row['math'] + $row['english'] ?></td>
        <td><?= $row['area']?></td>
        <td><?= $row['kind']?></td>
        <td><?= $row['sex']?></td>
        <td><?= $row['age']?></td>
        <td><?= $row['zhongxue']?></td>
    </tr>
</table>
这是
$row=mysql_fetch_assoc($res) ;//32行
$rows=mysql_fetch_assoc($ress);//34行

解决方案 »

  1.   

    才学php3天求帮忙,,,,,
      

  2.   

    $sql.="and area={$keyword0}";
    改为
    $sql.=" and area='{$keyword0}'";  //and前加一个空格,还有字符类型要加引号。
    下面的sql连接也这么改
    $ress=mysql_query("Select * from abc WHERE  kind= '{$keyword0}'",$conn) ;
      

  3.   

    ;同楼上 涉及到单双引号的区别,你可以看一下php的手册说明,预处理对象