php mysql 多表分级查询 10
我把每个主题的tid所有图片读出来,形成一个主题+多图片的列表,但是表3的表名是表2的一个对应值成生的,要怎么写...
我把每个主题的tid所有图片读出来,形成一个主题+多图片的列表,但是表3的表名是表2的一个对应值成生的,要怎么写
展开
1个回答
展开全部
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"><title>SQL多条件查询示例</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></select>面积:<input name="area" type="text"/>地址:<input name="addr" type="text"/><input name="btn" type="submit" value="搜索" /></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 ""; echo "面积:".$row['area']; echo ""; echo "居室:".$row['type']; echo ""; echo "价格:".$row['addr']; echo ""; //等等} ?>
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"><title>SQL多条件查询示例</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></select>面积:<input name="area" type="text"/>地址:<input name="addr" type="text"/><input name="btn" type="submit" value="搜索" /></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 ""; echo "面积:".$row['area']; echo ""; echo "居室:".$row['type']; echo ""; echo "价格:".$row['addr']; echo ""; //等等} ?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询