9 Replies - 1082 Views - Last Post: 02 July 2009 - 12:15 PM Rate Topic: -----

#1 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

mktime() error

Posted 02 July 2009 - 09:11 AM

Not sure what's wrong with it

<?php 
 function revertjailtime($str) {
		list($date, $time) = explode(' ', $str);
		list($year, $month, $day) = explode('-', $date);
		list($hour, $minute, $second) = explode(':', $time);

		$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
		return $timestamp;
	}
	$query = "SELECT username FROM login WHERE id='".$_SESSION["userid"]."'";
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result)){
	
	$username = $row['username'];
	
	$q = "SELECT time, length FROM jail WHERE username='".$username."'";
	$r = mysql_query($q);
	$v = mysql_fetch_array($r);
	$length = $v['length'];
	$lastActive = revertjailtime($v['time']);
	if ($lastActive + $length - time() > 0) { 
	} else {
		$delete="DELETE FROM jail WHERE username = '".$username."'";
		mysql_query($delete);
		
	}}
?>

<table width=50% border="1" bordercolor="#000000">
<tr><td align="center" bgcolor="#666666" colspan="3">Jail</td></tr>
<tr><td align="center" colspan="3"><img src="" alt="Jail"></td></tr>
<tr bgcolor="#666666"><td>Name</td><td>Time</td><td>Bust?</td></tr>
<? 
$jailq ="SELECT * FROM jail";
$jailr = mysql_query($jailq);
while ($row = mysql_fetch_array($jailr)){
	$username = $row['username'];
	$length= $row['length'];
	$time = $row['time'];

echo'
<tr><td>'.$username.'</td><td>';
 $lastActive = revertjailtime($time);
 echo $lastActive + $length - time();
echo'
</td><td>Bust Out</td></tr>'; }
?>


Is This A Good Question/Topic? 0
  • +

Replies To: mktime() error

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: mktime() error

Posted 02 July 2009 - 10:28 AM

What's the actual error??

Below are the functions I use for MySQL DateTime parsing:
public function CreateTimestamp($DateTime) {
		$Split = explode(" ", $DateTime);
		$Date = explode("-", $Split[0]);
		$Time = explode(":", $Split[1]);
		return mktime($Time[0], $Time[1], $Time[2], $Date[1], $Date[2], $Date[0]);
	}
	public function CreateFriendlyDate($timestamp) {
		if(date("W") == date("W", $timestamp)) {
			if(date("j") == date("j", $timestamp))
				return date("\\T\\o\\d\\a\\y \\a\\t H:i", $timestamp);
			return date("l \\a\\t H:i", $timestamp);
		} else {
			return date("jS M \\a\\t H:i", $timestamp);
		}
	}

Was This Post Helpful? 0
  • +
  • -

#3 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: mktime() error

Posted 02 July 2009 - 11:12 AM

sorry thought I put the error up:

Warning: mktime() expects parameter 1 to be long, string given in /home/a6490674/public_html/Mafia/jail.php on line 20
Was This Post Helpful? 0
  • +
  • -

#4 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: mktime() error

Posted 02 July 2009 - 11:32 AM

I only get the error way there's no info in the table...

But at times there will be no data table
Was This Post Helpful? 0
  • +
  • -

#5 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: mktime() error

Posted 02 July 2009 - 11:33 AM

If there's no data in the table, why are you calling a function that will work with the data?
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2910
  • View blog
  • Posts: 10,076
  • Joined: 08-August 08

Re: mktime() error

Posted 02 July 2009 - 11:35 AM

You could force type:
		return mktime((int)$Time[0], (int)$Time[1], (int)$Time[2], (int)$Date[1], (int)$Date[2],(int)$Date[0]);


Was This Post Helpful? 0
  • +
  • -

#7 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: mktime() error

Posted 02 July 2009 - 11:47 AM

Or you could just check if it's null/empty, and if it is then return something else...
I fail to see the point in using a function on something that you don't need to...

Yours,
Shane~

This post has been edited by ShaneK: 02 July 2009 - 11:48 AM

Was This Post Helpful? 0
  • +
  • -

#8 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: mktime() error

Posted 02 July 2009 - 11:53 AM

because it's a check to see if the play is still in jail or not.

it does it so it works out if the player still has time left in the jail and if so does nothing for the jail page but if time is up deletes it from the jail table.

I get the same error on other pages where it needs to check if players are in jail, incase they try and do something when they're not allowed while in jail

View PostShaneK, on 2 Jul, 2009 - 10:47 AM, said:

Or you could just check if it's null/empty, and if it is then return something else...
I fail to see the point in using a function on something that you don't need to...

Yours,
Shane~


cheers shane didn't think about using an if statement to actaully check if there is any data in the table before using the function :)
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2910
  • View blog
  • Posts: 10,076
  • Joined: 08-August 08

Re: mktime() error

Posted 02 July 2009 - 11:53 AM

Sometimes it's just easier to call the function, then disregard the results if it comes back with the wrong information, in this case: 943938000
;)
Was This Post Helpful? 0
  • +
  • -

#10 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: mktime() error

Posted 02 July 2009 - 12:15 PM

well after adding a if statement the error goes away cheers for all the help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1