php - 选择并减少 mysql 查询的字段值

标签 php mysql

我对 mysql_query 有疑问 我试图找到在线的成员,成员表中有一个字段“在线”总是随时间服务器更新。这是查询。

$ now = time ();
$ olline = mysql_num_rows (mysql_query ("select * from members where gender = 'Man' and (online - '$ now')> 10"));

在phpmyadmin中有7个成员按照上面的查询。 tp 我得到的值为 0。我的代码有什么问题。谢谢你的回答,抱歉英语不好

最佳答案

这些天你应该尝试并始终使用 Mysqli,因为不久 Mysql 将完全消失。您的代码的 Mysqli 示例:

 $mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$now = time(); // The time now for query calc
$gender = "Man"; // Gender for query

$stmt = $mysqli->stmt_init(); //Initialise statement
$stmt->prepare("SELECT * FROM members WHERE gender = ? AND (online - ?)> 10"); //Prepare the query
$stmt->bind_param('ss', $gender, $now); //Assign the query parameters
$stmt->execute(); // Execute the query
$stmt->store_result(); // store result of prepared statement
echo $stmt->num_rows;
$stmt->free_result(); //free up the $stmt var

关于php - 选择并减少 mysql 查询的字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18564788/

相关文章:

php - MATCH (somefeald) AGAINST ('+".$_GET ['search' ] ."' 在 bool 模式下) 不起作用

PHP/MySQL - 根据另一个结果选择

mysql - 两张表 - 如果年龄小于,则执行

php - DateTime方法链接问题

php - 如何编写返回按钮的代码?

PHP session 问题,请帮忙

c# - 将 DataGridView 值插入 MySql 数据库。 C#

mysql查询获取具体记录

php - 找不到: BlowfishPasswordHasher Cakephp

php - call_user_func_array 与 call_user_func