这是我的代码,但它不起作用;怎么了?
$ip = $_SERVER["REMOTE_ADDR"];
$con=mysqli_connect("DBHOST","DBUSER","DBPASS","DBNAME");
$check= 'SELECT * FROM ip WHERE ip = '.$_SERVER["REMOTE_ADDR"];
$rs = $con->query($check);
$data = mysqli_fetch_array($rs, MYSQLI_NUM);
$row_cnt = mysqli_num_rows($rs);
if( $row_cnt > 0 ) echo $row_cnt.' Records found';
答案 0 :(得分:0)
ip不是数字,它是文本(或varchar)。这就是你必须使用的原因:
$ check =“SELECT * FROM ip WHERE ip ='{$ _SERVER [”REMOTE_ADDR“]}'”;
答案 1 :(得分:0)
我认为,如果您只需要获取计数,请使用COUNT()
$sql = "SELECT COUNT(*) FROM ip WHERE ip = '".$_SERVER["REMOTE_ADDR"]."'";