mysql 倍数和条件 [英] mysql multiple and condition's

查看:24
本文介绍了mysql 倍数和条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何基于多个和条件查询一个mysql数据库...我试图在网上找到所有 18 岁以上的男性用户.

I need to know how to query a mysql database based on multiple and conditions... im trying to find all male users online above age 18.

php 代码:

$sql = mysql_query("Select * FROM `users` where `round`= '".$userData["round"]."',
    `sex` = 'm', `age` = '18', `online_stas` = 'online'
    ")or die(mysql_error());

推荐答案

阅读回复以及您仍然有错误的事实,我开始认为在 sex<中使用M"而不是m"的可能性/code> 字段.

Reading responses and the fact that you still have errors, I come to think the posibility of having "M" instead of "m" in sex field.

你可以试试:

$sql = mysql_query("SELECT * FROM `users`
                   WHERE UPPER(`sex`) = 'M'
                   AND `age` > 18
                   AND `online_stas` = 'online'")
       or die(mysql_error());

我根据您的声明删除了轮询,即您希望所有在线男性用户都超过 18 岁,但可以再次添加.其他可能的失败可以是 age 与字符串值 18 而不是数值 18 的比较,所以我也改变了它(尽管它可以工作并自动转换,但最好检查相同类型,如果有的话未来的变化).

I removed the round check based on your statement that you want all male users online being older than 18, but can be added again. Other posible fail can be the comparison of age with string value 18 instead of numeric value 18, so I changed that too (despite it may work and be converted automatically, but better to check with same types if something changes in a future).

试试看是否有效.

这篇关于mysql 倍数和条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆