我的IP是否在我的数据库中,如果是,请查找时间戳

时间:2011-10-13 13:50:05

标签: php mysql timestamp ip

好的,所以我想知道这个:

我的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

就我而言,就我而言,我有点陷入困境,有人帮助过我吗?

1 个答案:

答案 0 :(得分:2)

这应该可以解决问题,它应该获取时间戳并将其转换为人类可读格式,您可能还需要查找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");

}