好的,所以我想知道这个:
我的 IP 在我的数据库中吗?如果是,找到条目的时间戳。
到目前为止我有这个:
$ip = $_SERVER['REMOTE_ADDR'];
$myip = mysql_query("SELECT * FROM votes WHERE ip = '$ip'");
If(mysql_num_rows($myip) > 0){
//find timestamp and name it as a variable e.g $ipTime
这就是我所知道的,对于我的生活,我有点卡住了,有人帮助我吗?
最佳答案
这应该可以解决问题,它应该获取时间戳并将其转换为人类可读的格式,您可能还需要查找 PHP date()
函数来调整 $ date_format
根据您的喜好,可以在这里找到:http://php.net/manual/en/function.date.php
$ip = $_SERVER['REMOTE_ADDR']; // Fetch IP
$query = mysql_query("SELECT `timestamp` FROM `votes` WHERE (`ip` = '$ip')") or die(mysql_error()); // Queries IP
$amount = mysql_num_rows($query); // Amount of times listed (rows)
if ($amount > 0) { // If exists
$row = mysql_fetch_array($query);
$timestamp = $row['timestamp'];
$date_format = 'm F \a\t g:ia';
$date = date("$date_format", $timestamp); // Converts timestamp
echo("Your IP Address (".$ip.") is already listed at ".$date."");
} else {
echo("Your IP Address is not currently listed");
}
关于php - 我的IP是否在我的数据库中,如果有的话找到时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7755145/