PHP MySQL有效和可见的有效查询

时间:2013-09-26 12:22:30

标签: php mysql

如何为mysql数据库创建有效查询?

如何将WHERE visible = 1添加到此查询

SELECT *
FROM photographs
WHERE caption like %colname% or caption_2 like %colname%

2 个答案:

答案 0 :(得分:1)

SELECT *
FROM photographs
WHERE caption LIKE '%colname%'
OR caption_2 LIKE '%colname%' 
AND visible = 1

答案 1 :(得分:-1)

我认为我在代码中做错了,因为有些东西不起作用:) 告诉我所有结果

mysql_select_db($database_Photo_con, $Photo_con);
$query_rsPhoto = sprintf("SELECT * FROM photographs WHERE caption LIKE %s OR caption_2 LIKE %s  AND visible = 1 ", GetSQLValueString("%" . $colname_rsPhoto . "%", "text"),GetSQLValueString("%" . $colname_rsPhoto . "%", "text"));
$query_limit_rsPhoto = sprintf("%s LIMIT %d, %d", $query_rsPhoto, $startRow_rsPhoto, $maxRows_rsPhoto);
$rsPhoto = mysql_query($query_limit_rsPhoto, $Photo_con) or die(mysql_error());
$row_rsPhoto = mysql_fetch_assoc($rsPhoto);