简体   繁体   中英

Mysql compare IP address from table

I have a query in which i wanted to compare the ip address of system with the existed ip in records of table. but not able to compare the ip .. when i use normal query for counting records it works but not with Ip address in Where clause. my query is as below

SELECT count(product_id) AS count_likes, product_count FROM 
'._DB_PREFIX_.'count_likes WHERE product_id = '.$product_id.' AND ip-address =
"'.trim($ip_address).'";

I just want o compare ip and count no of matching records.

so far i got a just small mistake, So would like to post here

below is my modified query

$sql = 'SELECT * FROM '._DB_PREFIX_.'count_likes WHERE `product_id` = 
"'.$product_id.'" AND `ip_address` = "'.$ip_address.'"';

It has back quote difference to the column name ... Thanks to all for reply.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM