首页  >  文章  >  后端开发  >  javascript - 怎么实现我这个网页的查询方式?

javascript - 怎么实现我这个网页的查询方式?

WBOY
WBOY原创
2016-12-01 00:25:291130浏览

javascript - 怎么实现我这个网页的查询方式?

如图所示,我的网页后台使用php实现的,我想实现没有点击查询按钮时,在下面的表格中显示数据库中的全部项目信息;单击查询后,显示符合条件的项目,目前我的显示这种,我没有设置未点击查询的情况,应该用什么写?JS还是php?大体该怎么写
目前我只写了这个

<code> mysql_select_db("wuliu", $con);
                      

                          $result=mysql_query("SELECT * from content_info where title='$_POST[textfield22]' and submiter='$_POST[textfield322]' and area='$_POST[select]' and field='$_POST[select2]' and pass=0");
                           
                             

                          while($row = mysql_fetch_array($result))
                            {
                           
         

                            echo"<tr class="midTable1td2">";
                            echo "<td>
<input type="radio" name="radiobutton" value="radiobutton">";
                            echo "</td>";
                            echo "<td>".$row['UpdateDate'].$row['UpdateTime']./*2004-10-14 10:08:01*/"</td>";
                            echo "<td>".$row['area']."</td>";
                            echo "<td>".$row['field']."</td>";
                            echo "<td>".$row['title']."</td>";
                            echo "<td>".$row['submiter']."</td>";
                            echo "</tr>";
                          }

                  mysql_close($con);</code>

回复内容:

javascript - 怎么实现我这个网页的查询方式?

如图所示,我的网页后台使用php实现的,我想实现没有点击查询按钮时,在下面的表格中显示数据库中的全部项目信息;单击查询后,显示符合条件的项目,目前我的显示这种,我没有设置未点击查询的情况,应该用什么写?JS还是php?大体该怎么写
目前我只写了这个

<code> mysql_select_db("wuliu", $con);
                      

                          $result=mysql_query("SELECT * from content_info where title='$_POST[textfield22]' and submiter='$_POST[textfield322]' and area='$_POST[select]' and field='$_POST[select2]' and pass=0");
                           
                             

                          while($row = mysql_fetch_array($result))
                            {
                           
         

                            echo"<tr class="midTable1td2">";
                            echo "<td>
<input type="radio" name="radiobutton" value="radiobutton">";
                            echo "</td>";
                            echo "<td>".$row['UpdateDate'].$row['UpdateTime']./*2004-10-14 10:08:01*/"</td>";
                            echo "<td>".$row['area']."</td>";
                            echo "<td>".$row['field']."</td>";
                            echo "<td>".$row['title']."</td>";
                            echo "<td>".$row['submiter']."</td>";
                            echo "</tr>";
                          }

                  mysql_close($con);</code>

判断是否有post,有post才执行查询。

<code>if(isset($_POST)){

//这里是你发出来了那部分

}</code>

sql拼接有问题

将where语句分离出来。

<code>$where = "";
if(isset($_POST)){
    $where = "where title='$_POST[textfield22]' and submiter='$_POST[textfield322]' and area='$_POST[select]' and field='$_POST[select2]' and pass=0"";
}
$result=mysql_query("SELECT * from content_info ".$where);</code>

强烈建议参数化查询,防止注入
http://php.net/manual/zh/clas...

思路:
1.用分页查询的方式,每一页显示 10条信息
2.GET方式提交表单 拼装SQL语句
3。当没有查询条件的时候,则查询全部(分页)

php和js都可以。

你报错的原因是因为你调用$_POST变量错了。

$result=mysql_query("SELECT * from content_info where title='$_POST[textfield22]' and submiter='$_POST[textfield322]' and area='$_POST[select]' and field='$_POST[select2]' and pass=0");

改为

$result=mysql_query("SELECT * from content_info where title='".$_POST['textfield322']."' and submiter='".$_POST['textfield322']."' and area='".$_POST['select']."' and field='".$_POST['select2']."' and pass=0");

像楼上说的,最好是做个分页处理。mysql语句里面用limit去处理下。

不要这么拼接sql语句啊,分分钟搞出个sql注入出来。

建议在这个拼接语句的外部设置变量默认值,然后接收到post数据后校验并过滤后再覆盖旧默认值,再拼接查询语句吧。

这样子既安全,又解决你的需求。

1.$_POST数组里面的key对应的值要给一个默认值
2.加上分页
3.好好学习,天天向上

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn