timestamp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • up2trouble

    timestamp

    In mysql, I have a field defined as a time stamp. It is storing value
    as 0000-00-00 00:00:00. It to store it in seconds.

    <?PHP
    $entered = mktime();
    echo "<INPUT TYPE='text' NAME='$entered' VALUE='$entered ' SIZE='13'
    READONLY>";
    ?>

    What am i doing wrong?
  • Onur Buyukceran

    #2
    Re: timestamp

    The TIMESTAMP data type has varying properties, depending on the MySQL
    version and the SQL mode the server is running in. You should read the
    following to understand it better. http://dev.mysql.com/doc/refman/5.0/en/datetime.html

    OR

    You can store $entered as LONGINTEGER, since mktime returns the result
    as LONGINTEGER.

    On May 15, 4:19 am, up2trouble <lynettesm...@g mail.comwrote:
    In mysql, I have a field defined as a time stamp.  It is storing value
    as 0000-00-00 00:00:00.  It to store it in seconds.
    >
    <?PHP
    $entered = mktime();
    echo "<INPUT TYPE='text' NAME='$entered' VALUE='$entered ' SIZE='13'
    READONLY>";
    ?>
    >
    What am i doing wrong?

    Comment

    • up2trouble

      #3
      Re: timestamp

      I changed it to bigint didn't see long one. Now it stores a 0. It
      is not taking my value from mktime(). I read your suggested material.
      I understood none of it.

      Comment

      • up2trouble

        #4
        Re: timestamp

        I don't know if this helps, but I'm trying to print unique codes for
        use in a db. The problem is that when I need more codes I only want
        the new ones to print out not the ones that have been already
        printed. I thought that I could just set a time and say to print
        codes that were generated at a time greater than the time entered.
        Instead of codes, I get: Query 2 failed cause: You have an error in
        your SQL syntax; check the manual that corresponds to your MySQL
        server version for the right syntax to use near '18:47:17' at line 1.

        <?PHP
        if(isset($_POST['printcodes']))
        {
        $gettime = date("Y-m-d H:i:s", mktime());
        $sql= "SELECT * FROM $db_table10 WHERE entered < $gettime";
        $result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
        ' . mysql_error());
        $num = mysql_num_rows( $result);

        echo "<FIELDSET><FON T SIZE='+1' COLOR='#FF0000' >These are your codes.
        Just save to your desktop, then
        open in Word to print.</FONT></FIELDSET";

        while ($row = mysql_fetch_arr ay ($result))
        {
        echo "<P STYLE='text-align: justify; width: 550px;'>This is the
        anonymous id code which will allow you to take your end of class
        survey.
        You will need a new code for each class. ";
        echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
        echo "Your case sensitive code is :<BR>";
        echo "<FONT SIZE='+1'><STRO NG>{$row['id']}</STRONG></FONT></P>";
        }
        }
        ?>


        Comment

        • Jerry Stuckle

          #5
          Re: timestamp

          up2trouble wrote:
          I changed it to bigint didn't see long one. Now it stores a 0. It
          is not taking my value from mktime(). I read your suggested material.
          I understood none of it.
          >
          Please learn how to reply properly. You were not responding to
          yourself. Also, please quote the relevant parts (as in here).

          As to your problem - you didn't give us enough information to go on -
          like the real code you're using. Additionally, you need to determine
          how you want the data stored - a unix timestamp works, but there are
          valid reasons for using a datetime field, also (which is off topic in a
          PHP newsgroup, and should be discussed in comp.databases. mysql).

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • up2trouble

            #6
            Re: timestamp

            On May 14, 9:54 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            up2trouble wrote:
            I changed it to bigint didn't see long one. Now it stores a 0. It
            is not taking my value from mktime(). I read your suggested material.
            I understood none of it.
            >
            Please learn how to reply properly. You were not responding to
            yourself. Also, please quote the relevant parts (as in here).
            >
            As to your problem - you didn't give us enough information to go on -
            like the real code you're using. Additionally, you need to determine
            how you want the data stored - a unix timestamp works, but there are
            valid reasons for using a datetime field, also (which is off topic in a
            PHP newsgroup, and should be discussed in comp.databases. mysql).
            >
            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstuck...@attgl obal.net
            =============== ===
            I want a timestamp to store seconds and not a date/time format. The
            only thing I took out of the code was the url for my page.

            <?PHP
            if(isset($_POST['printcodes']))
            {
            $gettime = date("Y-m-d H:i:s", mktime());
            $sql= "SELECT * FROM $db_table10 WHERE created < $gettime";
            $result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
            ' . mysql_error());
            $num = mysql_num_rows( $result);

            echo "<FIELDSET><FON T SIZE='+1' COLOR='#FF0000' >These are your codes.
            Just save to your desktop, then
            open in Word to print.</FONT></FIELDSET";

            while ($row = mysql_fetch_arr ay ($result))
            {
            echo "<P STYLE='text-align: justify; width: 550px;'>This is the
            anonymous id code which will allow you to take your end of class
            survey.
            You will need a new code for each class. ";
            echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
            echo "Your case sensitive code is :<BR>";
            echo "<FONT SIZE='+1'><STRO NG>{$row['id']}</STRONG></FONT></P>";
            }
            }

            ?>

            I should get a page of codes to print. It was working fine. However,
            the problem is that when I need more codes I only want
            the new ones to print out not the ones that have been already
            printed. I thought that I could just set a time and say to print
            codes that were generated at a time greater than the time entered.
            Instead of codes, I get: Query 2 failed cause: You have an error in
            your SQL syntax; check the manual that corresponds to your MySQL
            server version for the right syntax to use near '18:47:17' at line 1.

            When I create the code, I add in timestamp. I changed created to
            entered and made varchar(25) in db. It doesn't keep a default value
            and leaves what I entered in seconds.

            $created = mktime();
            $sql= "INSERT into $db_table10 (id, created) VALUES
            ('$random','$cr eated')" ;



            Comment

            • Michael Austin

              #7
              Re: timestamp

              up2trouble wrote:
              I don't know if this helps, but I'm trying to print unique codes for
              use in a db. The problem is that when I need more codes I only want
              the new ones to print out not the ones that have been already
              printed. I thought that I could just set a time and say to print
              codes that were generated at a time greater than the time entered.
              Instead of codes, I get: Query 2 failed cause: You have an error in
              your SQL syntax; check the manual that corresponds to your MySQL
              server version for the right syntax to use near '18:47:17' at line 1.
              >
              <?PHP
              if(isset($_POST['printcodes']))
              {
              $gettime = date("Y-m-d H:i:s", mktime());
              $sql= "SELECT * FROM $db_table10 WHERE entered < $gettime";
              $result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
              ' . mysql_error());
              $num = mysql_num_rows( $result);
              >
              echo "<FIELDSET><FON T SIZE='+1' COLOR='#FF0000' >These are your codes.
              Just save to your desktop, then
              open in Word to print.</FONT></FIELDSET";
              >
              while ($row = mysql_fetch_arr ay ($result))
              {
              echo "<P STYLE='text-align: justify; width: 550px;'>This is the
              anonymous id code which will allow you to take your end of class
              survey.
              You will need a new code for each class. ";
              echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
              echo "Your case sensitive code is :<BR>";
              echo "<FONT SIZE='+1'><STRO NG>{$row['id']}</STRONG></FONT></P>";
              }
              }
              ?>
              Reading documentation can save you a lot of headaches:

              PHP answer:
              <?php
              list($usec, $sec) = explode(" ", microtime());
              print $usec . "\n";
              print $sec . "\n";
              ?>
              RESULT:
              Content-type: text/html
              X-Powered-By: PHP/4.3.10

              microsecond - 0.82285100
              unix time in sec since epoch 1210823761

              No, this is not a PHP answer, but given the proposed usage, it is a
              better solution... and it works...

              mysqlselect UNIX_TIMESTAMP( ), from_unixtime( UNIX_TIMESTAMP( ));
              +------------------+----------------------------------+
              | UNIX_TIMESTAMP( ) | from_unixtime( UNIX_TIMESTAMP( )) |
              +------------------+----------------------------------+
              | 1210822584 | 2008-05-14 22:36:24 |
              +------------------+----------------------------------+

              you can use it in an insert statement:

              insert into table values (1,'test',unix_ timestamp());


              mysqlcreate table aa (a bigint);
              Query OK, 0 rows affected (0.02 sec)

              mysql>
              mysqlinsert into aa values (unix_timestamp ());
              Query OK, 1 row affected (0.00 sec)

              mysqlselect * from aa;
              +------------+
              | a |
              +------------+
              | 1210822778 |
              +------------+
              1 row in set (0.00 sec)

              Comment

              • Jerry Stuckle

                #8
                Re: timestamp

                up2trouble wrote:
                On May 14, 9:54 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                >up2trouble wrote:
                >>I changed it to bigint didn't see long one. Now it stores a 0. It
                >>is not taking my value from mktime(). I read your suggested material.
                >>I understood none of it.
                >Please learn how to reply properly. You were not responding to
                >yourself. Also, please quote the relevant parts (as in here).
                >>
                >As to your problem - you didn't give us enough information to go on -
                >like the real code you're using. Additionally, you need to determine
                >how you want the data stored - a unix timestamp works, but there are
                >valid reasons for using a datetime field, also (which is off topic in a
                >PHP newsgroup, and should be discussed in comp.databases. mysql).
                >>
                >--
                >============== ====
                >Remove the "x" from my email address
                >Jerry Stuckle
                >JDS Computer Training Corp.
                >jstuck...@attg lobal.net
                >============== ====
                >
                I want a timestamp to store seconds and not a date/time format. The
                only thing I took out of the code was the url for my page.
                >
                <?PHP
                if(isset($_POST['printcodes']))
                {
                $gettime = date("Y-m-d H:i:s", mktime());
                $sql= "SELECT * FROM $db_table10 WHERE created < $gettime";
                $result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
                ' . mysql_error());
                $num = mysql_num_rows( $result);
                >
                echo "<FIELDSET><FON T SIZE='+1' COLOR='#FF0000' >These are your codes.
                Just save to your desktop, then
                open in Word to print.</FONT></FIELDSET";
                >
                while ($row = mysql_fetch_arr ay ($result))
                {
                echo "<P STYLE='text-align: justify; width: 550px;'>This is the
                anonymous id code which will allow you to take your end of class
                survey.
                You will need a new code for each class. ";
                echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
                echo "Your case sensitive code is :<BR>";
                echo "<FONT SIZE='+1'><STRO NG>{$row['id']}</STRONG></FONT></P>";
                }
                }
                >
                ?>
                >
                I should get a page of codes to print. It was working fine. However,
                the problem is that when I need more codes I only want
                the new ones to print out not the ones that have been already
                printed. I thought that I could just set a time and say to print
                codes that were generated at a time greater than the time entered.
                Instead of codes, I get: Query 2 failed cause: You have an error in
                your SQL syntax; check the manual that corresponds to your MySQL
                server version for the right syntax to use near '18:47:17' at line 1.
                >
                When I create the code, I add in timestamp. I changed created to
                entered and made varchar(25) in db. It doesn't keep a default value
                and leaves what I entered in seconds.
                >
                $created = mktime();
                $sql= "INSERT into $db_table10 (id, created) VALUES
                ('$random','$cr eated')" ;
                >
                >
                >
                >
                This was not the code in your first post - and you didn't have any code
                in your second one. That is why I asked.

                Your query fails because a datetime value needs to be in single quotes
                in the query, i.e.

                $sql= "SELECT * FROM $db_table10 WHERE created < '$gettime'";

                And your other problems are SQL related - not PHP. I suggest you follow
                up in comp.lang.mysql - which is where you should be asking
                MySQL-related questions.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                Working...