开发者

Wordpress Custom Table Query using Multiple Values

I have been researching the last hour of whether or not I can run a query within wordpress on a custom table that I made using two WHERES. Now I'm new to mysql and php ( 9 months in ) and am just wondering if there is a way to do it besides a AND.

Here is an example of my code

$check_current = $wpdb->get_row("SELECT * FROM $weather_table WHERE status = 'current' AND  condition = $current_weather");

status and condition are both fields and I'm trying to find out whether both exist to rewrite the current field. 开发者_JS百科The closest I've come is possibly using the prepare function in Wordpress and php but don't know what that is exactly just know it helps with sql injection and security. Can you run a multiple value query in Wordpress?


Using the AND operator in MySQL is the right way to test for a compound condition.

Be sure to put quotes around any variables (like $current_weather) if the underlying data type is a string.

Also, best practice is to avoid using "*" in the select. Rather, explicitly declare the fields you want to return. This is good for performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜