Jump to content

UNIXTIME Error


millsy007

Recommended Posts

I am trying to run a script to populate my tables:

 

<?php

$date_start = '01/30/2009';

$date_end = '12/31/2009';

$runs_per_day = array ( 9, 12, 16, 22 );

$routes = array ( 1, 2, 3, 4, 5 );

$dh = 'localhost';
$dn = 'coach';
$du = 'user';
$dp = 'pass';



mysql_connect ( $dh, $du, $dp ) or die ( mysql_error () );



mysql_select_db ( $dn );




$date_start = strtotime ( $date_start );



$date_end = strtotime ( $date_end );



$id = 1;



while ( $date_start <= $date_end )



{





foreach ( $runs_per_day AS $departure_time )





{







mysql_query ( "INSERT INTO Shuttle VALUES ( " . $id . ", FROM_UNIXTIME ( " . ( ( $departure_time * 3600 ) + $date_start ) . " ) );" ) or die ( mysql_error () );







foreach ( $routes AS $route )







{









mysql_query ( "INSERT INTO journey VALUES ( " . $id . ", " . $route . ", 0 );" );







}







$id += 1;





}





$date_start += 86400;



}
?>

 

However I get the error: FUNCTION beachh_shuttle.FROM_UNIXTIME does not exist

Link to comment
https://forums.phpfreaks.com/topic/143935-unixtime-error/
Share on other sites

Thanks but I definately have a comma. I tried doing an echo:

 

$sql="INSERT INTO shuttle VALUES ( " . $id . ", FROM_UNIXTIME ( " . ( ( $departure_time * 3600 ) + $date_start ) . " ) )";
echo $sql;
mysql_query ($sql) or ;

 

And I got:

INSERT INTO shuttle VALUES ( 1, FROM_UNIXTIME ( 1233324000 ) )INSERT INTO shuttle VALUES ( 2, FROM_UNIXTIME ( 1233334800 ) )INSERT INTO shuttle VALUES ( 3, FROM_UNIXTIME ( 1233349200 ) ) ..... etc

 

I am a little confused by the date formatting what I need is there to be a record of each shuttle trip, of which there are 4 daily at 9:00 12:00 16:00 and 22:00 How would I get these times into the correct format?

Link to comment
https://forums.phpfreaks.com/topic/143935-unixtime-error/#findComment-755846
Share on other sites

There is a white-space problem. I removed all the excess white-space and the ; on the end of the sql statement and the following query recognizes the FROM_UNIXTIME function -

 

mysql_query ("INSERT INTO Shuttle VALUES (" . $id . ", FROM_UNIXTIME(" . ( ( $departure_time * 3600 ) + $date_start ) . "))") or die (mysql_error());

 

Link to comment
https://forums.phpfreaks.com/topic/143935-unixtime-error/#findComment-756106
Share on other sites

Hi this now runs, thanks for the help  ;D

However part of the query isnt doing what it should so any advice would be great. What I expected to happen was for each shuttle 5 journeys take place, I wanted to create a record for each of these jouneys by insertiting the 'shuttle_id', 'route_id' and 'occupancy' in a 'journey' table, however nothing is going in and I get no error?

 

the journey table has

id

shuttle_id

route_id

occupancy

 

should i specify this in the insert statement?

Link to comment
https://forums.phpfreaks.com/topic/143935-unixtime-error/#findComment-756309
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.