
正文
php查询数据库条件 php查询sqlserver数据库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php+mysql多条件多值查询
PHP+Mysql多条件多值查询示例代码:
index.html代码:
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
titleSQL多条件查询示例/title
/head
body
form method="post" action="deal.php"
h1房屋出租/h1
房屋类型:select name="type"
option value="1"一居室/option
option value="2"二居室/option
option value="3"三居室/option
/selectbr/
面积:input name="area" type="text"/br/
地址:input name="addr" type="text"/br/
input name="btn" type="submit" value="搜索" /br/
/form
/body
/html
deal.php文件:
?php
//连接数据库
$conn=mysql_connect("localhost","root","");
//选择数据库
$db=mysql_select_db("数据库名");
//接收 参数
$type=$_POST['type'];
$area=$_POST['area'];
$addr=$_POST['addr'];
//SQL语句主题
$query="select * from room where ";
//根据条件和传的值拼接sql语句
//判断面积不为空
if($type!=""){
//然后根据具体面积分情况拼接
switch($type){
case 1:
//一居室
$query.=" room_type=1";
break;
case 2:
$query.=" room_type=2";
break;
case 3:
$query.=" room_type=3";
break;
}
}
//面积
if($area!=""){
$query.=" and area ={$area}";
}
//地址
if($addr!=""){
$query.=" and addr like '%{$addr}%'"; //地址
}
//执行查询
$result=mysql_query($query);
//遍历结果
echo "搜搜结果如下:";
while($row=mysql_fetch_array($result)){
echo "地址:".$row['addr'];
echo "br/";
echo "面积:".$row['area'];
echo "br/";
echo "居室:".$row['type'];
echo "br/";
echo "价格:".$row['addr'];
echo "br/";
//等等
}
?
相关问答
Q1: php 多条件查询数据库MySQL
SELECT * FROM `表名` WHERE bookid=22
获取BOOKID为22的记录,输出$uid=
if(strpos($uid,"2")!==false):echo"包含";else:echo"不包含";endif;
判断UID中是否含有2
MYSQLI方法统计数量
$num=mysqli_num_rows(mysqli_query($mysqli,"SELECT id FROM `表名` where pinglun=1"));
统计该表中pinglun=1的记录数量
Q2: 用PHP在查询数据库时,不等于这个条件怎么写啊?
SQL语句写错php查询数据库条件了
1.下载SQLyog工具,这个工具用图形化的方式来管理Mysql,很方便的
你把你的语句放到里面执行一下
2.下载mysql手册,网上到处都是
php查询数据库条件我写php查询数据库条件了一个数据库查询的例子(数据库名为tarena,表名为test),你运行一下就好了
?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$result = mysql_query("SELECT * FROM tarena.test
where over='1' and showl='1' and aaa'aaa'
order by id desc limit 5")or die("Invalid query: " . mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows == NULL)
{
return NULL;
}
else
{
$num_fields = mysql_num_fields($result);
$fields=Array();
$i = 0;
echo "table border='1' width='200'";
echo 'tr';
while ($i $num_fields)
{
$currfield = mysql_fetch_field($result);
echo 'td'.$currfield-name.'/td';
array_push($fields,$currfield-name);
$i++;
}
echo '/tr';
echo 'tr';
while($row = mysql_fetch_array($result)) {
foreach ($fields as $field) {
echo 'td'.$row[$field].'/td';
}
}
echo '/tr';
echo '/table';
}
?
Q3: php使用$cl变量作为查询数据库语句的条件,写法是什么?
由于face字段是字符型的,所以需要单引号。
$cl = 01;
$sql = 'SELECT * FROM `#@__guestbook` WHERE ischeck=1 and face='{$cl}' ORDER BY id DESC';
Q4: PHP实现按条件查询 数据库内容并在当前页面显示,如下图,谢谢提供下思路
页面加载时 distinct 一下班级php查询数据库条件,把得到php查询数据库条件的列表加载到班级的 dropdownlist里php查询数据库条件,至于性别的直接手动添加男女就行了。
点击查询的时候 select * from xxx where 班级=班级dorpdownlist.text and 性别=性别dorpdownlist.text
关于php查询数据库条件和php查询sqlserver数据库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







