Reputation: 943
OK, so I want to know this:
Is my IP in my database? If yes, find the timestamp of entry.
So far I have this:
$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
Thats as far as I've got, and for the life of me, I'm a little stuck, anyone help me?
Upvotes: 0
Views: 321
Reputation: 2376
This should do the trick, it should get the timestamp and convert it to a human readable format, you may also want to look up the PHP date()
function to adjust the $date_format
to your liking which can be found here: 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");
}
Upvotes: 2