I have a large database that I need to convert time from normal date time format to unix timestamp.

Php is still new to me so I have been reading and am I on the right path? I have over 4000 entries now that need to be converted so I want to query the database and display the unix timestamps for each in a column

Here is my code although it isn't working correctly can someone help me please.


<?php 

################################
## Database Connection Values ##
################################
$host     = "localhost";       
$dbuser = "xxxxxx";
$dbpass = "xxxxxxx";
$database = "xxxxxxxxxxx"; $db_connection = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); $sql = "SELECT UNIX_TIMESTAMP(date) FROM xxxxxxxxxxx"; $result = mysql_query($sql, $db_connection); while($row = mysql_fetch_array($result)){ echo $result; } ?>

Any help would be great

THANKS!

    you should use [php][/php] tags around php code it makes it more readable.

    <?php 
    //I'm aliasing your column
    $sql = "SELECT UNIX_TIMESTAMP(date)  as unix_date
            FROM xxxxxxxxxxx";
    
    $result = mysql_query($sql, $db_connection); 
    
    while($row = mysql_fetch_array($result)){ 
        //you're echoing the resource
        //echo $result;
        //try this instead
        echo $row['unix_date'] . '<br />';
    }
    ?> 
    

      Ok, For some reason I am getting this error

      Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in X:\WebFolders\test.php on line 19

      Any thoughts?

        <?php 
        if(($result = mysql_query($sql, $db_connection)) === FALSE)
            die(mysql_errno() . ": " . mysql_error()); 
        ?> 
        

          The error comes back saying no database selected.
          I have made sure I have typed everything correctly. Everything checks out. The database is there and the table exsists with data in it.

            Ok I have done some reading on mysql and searched on google. But here is the error

            Not connected : Unknown MySQL Server Host '$host' (11001)

            Yet I can connect to it using ems mymanager software. All it is is a gui interface.

            Some other people have had this problem and there was no solutions.

            Any ideas?

            We recently upgraded our mysql server to the latest version could that be the problem, possible bug?

              Doubt it's a bug. Could we see the code as it stands now, please?

                Finally got it to work......

                <?
                
                ################################
                ## Database Connection Values ##
                ################################
                $host     = "localhost";       // mysql host (localhost in most cases)
                $dbuser   = "xxxxx";            // database username
                $dbpass   = "xxxxxxxx";        // database password
                $database = "xxxxxxxxxxx";     // database name
                
                $dbconn = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
                mysql_select_db($database, $dbconn);
                
                $sql = "SELECT UNIX_TIMESTAMP(date)  as unix_date 
                        FROM appointments"; 
                
                $result = mysql_query($sql, $dbconn);  
                
                while($row = mysql_fetch_array($result)){  
                echo $row['unix_date'] . '<br />'; } ?>
                  Write a Reply...