phpMyAdmin中mysql查询语句中分号注意事项
2012-05-16 19:19
405 查看
最近又在看php,新学者,菜鸟的说》》》》
今天做了一个简单的mysql查询功能,
index.html查询条件页面:
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8">
<title>searchpage</title>
</head>
<body>
<formaction="search.php"method="post">
<tablewidth="80%"border="1"align="center"cellpadding="2"bordercolor="#0000FF"bordercolorlight="#7D7DFF"bordercolordark="#0000A0"bgcolor="#E8E8E8">
<tr>
<tdwidth="20%"height="29"align="left"valign="middle">装饰理念</td>
<tdwidth="88%"height="29"align="left">
<selectname="idea"id="select1">
<optionvalue="实用简约">实用简约</option>
<optionvalue="朴素设计">朴素设计</option>
</select>
</td>
</tr>
<tr>
<tdwidth="20%"height="29"align="left"valign="middle">房屋类型</td>
<tdwidth="88%"height="29"align="left">
<selectname="housetype"id="select2">
<optionvalue="二室一厅">二室一厅</option>
<optionvalue="三室一厅">三室一厅</option>
</select>
</td>
</tr>
<tr>
<tdwidth="20%"height="29"align="left"valign="middle">装修风格</td>
<tdwidth="88%"height="29"align="left">
<selectname="style"id="select3">
<optionvalue="田园风格">田园风格</option>
<optionvalue="中式风格">中式风格</option>
</select>
</td>
</tr>
<tr>
<tdwidth="20%"height="29"align="left"valign="middle">房屋用途</td>
<tdwidth="88%"height="29"align="left">
<selectname="app"id="select4">
<optionvalue="自住">自住</option>
<optionvalue="出租">出租</option>
</select>
</td>
</tr>
<tr>
<tdwidth="20%"height="29"align="left"valign="middle">期望价格</td>
<tdwidth="88%"height="29"align="left">
<selectname="price"id="select5">
<optionvalue="A">50000以下</option>
<optionvalue="B">50000以上</option>
</select>
</td>
</tr>
<tr>
<tdwidth="20%"height="29"align="left"valign="middle">发布时间</td>
<tdwidth="88%"height="29"align="left">
<selectname="pubdate"id="select6">
<optionvalue="A">最近一周</option>
<optionvalue="B">最近一个月</option>
<optionvalue="C">最近三个月</option>
<optionvalue="D">最近一年</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><inputtype="submit"value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
search.php
运行的结果为:
注意这一句:
可见,对于条件字符,应使用双引或者单引均可,(而非``):
今天做了一个简单的mysql查询功能,
index.html查询条件页面:
装饰理念 | 实用简约朴素设计 |
房屋类型 | 二室一厅三室一厅 |
装修风格 | 田园风格中式风格 |
房屋用途 | 自住出租 |
期望价格 | 50000以下50000以上 |
发布时间 | 最近一周最近一个月最近三个月最近一年 |
<html> <head> <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"> <title>searchresult</title> </head> <body> <tablealign="center"> <?php $idea=$_POST['idea']; $housetype=$_POST['housetype']; $style=$_POST['style']; $app=$_POST['app']; $price=$_POST['price']; $pubdate=$_POST['pubdate']; #echo$idea,'',$housetype,'',$style,'',$app,'',$price,'',$pubdate; $conn=mysql_connect("localhost","thoupin","D3w89X7z"); mysql_select_db("sample"); $query="select*from`case`where`idea`='".$idea."'"; #housetype if($housetype!=""){ $query.="&&`housetype`='".$housetype."'"; } #style if($style!=""){ $query.="&&`style`='".$style."'"; } #app if($app!=""){ $query.="&&`app`='".$app."'"; } #price /* if($price!=""){ switch($price){ case"A": $query.="&&`price`<50000"; break; case"B": $query.="&&`price`>=50000"; break; } } #pubdate if($pubdate!=""){ switch($pubdate){ case"A": $query.="&&TO_DAYS(NOW())-TO_DAYS(`pubdate`)<=7"; break; case"B": $query.="&&TO_DAYS(NOW())-TO_DAYS(`pubdate`)<=30"; break; case"C": $query.="&&TO_DAYS(NOW())-TO_DAYS(`pubdate`)<=91"; break; case"D": $query.="&&TO_DAYS(NOW())-TO_DAYS(`pubdate`)<=183"; break; } } */ #result $query.="orderby`pid`limit0,20;"; @mysql_query("setnames'utf8'",$conn); $result=mysql_query($query,$conn); if($result){ $rows=mysql_num_rows($result); if($rows!=0){ while($myrow=mysql_fetch_array($result)){ echo'<tr>'; echo"<tdwidth='15'height='12'><inputname='t1'type='radio'value=''/></td>"; echo"<tdwidth='540'height='12'> $myrow[pid] $myrow[idea] $myrow[style]($myrow[housetype]) <fontstyle='font-size:9pt'>[$myrow[pubdate]]</font>"; echo'</td>'; echo"<tdwidth='75'height='12'><ahref=''target='_blank'>详细信息</a></td>"; echo'</td>'; } } }else{ echo"<tr><td><divalign='center'><br/><br/>没有符合查找条件的记录!</div></td></tr>"; } echo"<hrwidth=\"100%\"size=\"1\">"; ?> </table> </body> </html>
运行的结果为:
1实用简约田园风格(二室一厅)[2012-02-1713:23:17] |
$query="select*from`case`where`idea`='".$idea."'"; 当时我是直接一律用的单引号(即"'"),然后就是如下结果:
尔后将单引号改为``后可以得到正确结果:
可见在phpMyAdmin的查询环境(windowsutf-8)中,单引号应为``; 但是绝不是一律使用``,例如下列情况:
可见,对于条件字符,应使用双引或者单引均可,(而非``):
另外,对于数字,需不需要引号为所谓,但建议加上。 对于表名,列名,应使用``,而对于条件数据,应使用'',或者""。
相关文章推荐
- sql查询语句的一些注意事项
- Mysql查询缓存的注意事项
- 关于MySQL查询赋值的注意事项
- phpmyadmin导出mysql查询的数据为excel分号格式转换为列
- Hql语句注意事项总结 批量删除 批量查询
- LOAD DATA INFILE语句导入数据进入MySQL的一些注意事项
- mysql sql语句书写注意事项
- 用python写入和查询mysql及注意事项
- MySQL杂项(索引注意事项 快速导入导出数据 锁 字符集 慢查询)
- Mysql查询大表注意事项
- 使用Navicat for Mysql执行sql查询文件注意事项
- 关于MySql查询一个时间段的注意事项
- 项目发布到Linux注意事项。Linux系统SQL语句查询的表字段名不能大写。
- 慢查询mysql processlist的注意事项
- MySQL数据库查询语句注意事项
- Hibernate写查询语句注意事项
- mysql 查询注意事项
- MySQL SQL语句之join 过滤注意事项
- Hibernate使用sql语句查询,返回实体类型的方法及注意事项
- 关于MySql中数据库、表的操作以及增删改查等一些SQL语句注意事项