PHP - Php Mysql Time
Hi guys.
I want to make two records. 1)Current time and date. 2)Time and date after 20 seconds. Now i have this piece of code: Code: [Select] <?php $hr = 0; $min = 0; $sec = 11; echo $date = date("Y-m-d H:i:s");echo "\n"; echo $modified = time() + (0 * 0 * 0 * 20); ?> I think there is something wrong with this line: Code: [Select] <?php echo $modified = time() + (0 * 0 * 0 * 20);1 ?>I get something like this: 1324668576. You can check this http://kingstonuni.atspace.co.uk/RPG/muziejus.php link to get a better view. Any help would be appreciated. Thank you. Similar TutorialsHello guys. I am creating a PHP/mySQL based RPG. I have implemented training feature in it. So i want to make training possible every 15 minutes or so. Can you give me an advice how to achieve that? Thank you! hello guys. i sitting here at my pc , have used alot days on google and forums. but i just cant seem to find what i am looking for so i hope that anyone here got a min to tell me what to do okai soo what i am looking for is a php / mysql script that can countdown for a user , when its finish add a number ( to usertabel[2]. and the problem is it need to do it also if the user closes the browser. i am total lost , have no ide to fix / wihte it Sorry for my spelling i am danish I need to write a bit of code to select some mp3's (actually, just the titles) from a database...but I need to select them based on last play (which is a timestamp field in the DB) AND I need to select 14 minutes worth of them (and not more than 15 minutes). I currently do NOT know how long each song is... So, if every song was 2 minutes long, I would need 7 songs. If each song was 3 minutes long, I'd need to select 5 of them. I currently do NOT have a length field in the db (the boss sprung this on me after I designed the DB). A few questions: Would it be best to have a column of TIME (mysql time...not the name of the column)? Would it be best to have a column for the raw size of the file (each file is the same bitrate, so I could do the math - plus it would be probably be easier to import raw filesize using php into the db) Would it be easier to do something else? Once we answer that, I'll start with some code...and probably be back for help! hey, here is the code I am using. Code: [Select] mysql_connect("localhost","XXXXXX","XXXXXX") or die("Could not connect."); mysql_select_db("XXXXXX"); $query="SELECT * FROM VIDEO_SESSIONS"; $result=mysql_query($query); while ($db_field = mysql_fetch_assoc($result)) { $timeslider = $db_field['timeslider']; } $message=$_POST['message']; $name=$me['first_name']; if(isset($_POST['submit'])){ if(strlen($message)<1) { print "You did not input a message"; } else if(strlen($name)<1) { print "Please login with Facebook to post a message"; } else { $insertmessage="INSERT INTO CHAT_SESSIONS (user_id,user_message,current_time) VALUES ('$name', '$message', '$timeslider')"; mysql_query($insertmessage); echo mysql_error(); } } ?> I am getting this error everytime I try and INSERT into the database " 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 'current_time) VALUES ('Luke', 'Hello?', '00:23:00')' at line 2 " it works fine without the '$timeslider' which is a time stored on the database in the format 00:00:00 why does it not want to store the time back in a different table.. same format!? Hey guys, im having a slight issue with comparing mysql time stamp. I'm using the timestamp in mysql to show how many people are online with in 5 minutes. $sql = mysql_query("SELECT name,id FROM users WHERE DATE_SUB(NOW(), INTERVAL 5 MINUTE) <= last_active ORDER BY id ASC"); But I want to grab last_active from the data base and compare it like below. I dont know if strtotime just doesnt compare with mysql time stamp or what? if($last_active > strtotime('-5 minutes')) { echo "<td>Online</td>"; }else{ echo "<td>Offline</td>"; } I created a "statistics of site" page, stats.php. Currently stats.php updates every visit, that's over 25 queries for every visit, with over 9,000 visits a day, I wish to cut down. What is the best way to make it so all queries are done every hour, therefore requiring less queries to the database? I assume the best way to go at this would be either to run a time() based script every 60 minutes and: - update this to a new field, then stats.php will require 1 query every visit, plus the 1 every hour. or - update a text file and read that each stats.php visit, meaning just the 1 query every hour. Now, I understand the second option will run much less queries overall, but is it the best way to go? Is there a better way to go about doing this? Is there any simple way I can log the execution time of each mysql query that is executed on a page, maybe with a register shutdown function, I have been trying to profile and reduce execution time of the CRM / tracking system at work and have used a register shutdown function to log page execution time. We were unsure of wither it was the internet connection, browsers having a hard time rendering nested tables(the code is OLD), or mysql queries taking too long to execute. Yesterday I started re-coding a script and I got to a query, it returned one row/field and had a limit 1, but it searched for an md5 has in the where clause, as soon as I added this query in my re-code it took execution time from 1s to 13s, I ran the query in phpmyadmin and the execution time was 0.5s, this was running in a loop which returned about 20 rows, I added an index on the md5 hash field and the query then took 0.0005s to load, I now want to do this for all scripts on the system. Any ideas? Thanks // EDIT, please note that I don't have shell access, I only have access to the scripts, plesk panel and PHPmyadmin I get a "No database selected" error whenever I submit information on my register.php page, which is: <?php include_once('includes/config.php'); include_once('functions.php'); $return_content = AccountRelated(null, null, 3); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style/style.css" /> <title><?php echo $title; ?></title> </head> <body> <div class="logo"><a href="index.php"><img src="style/images/logo.png" border="0"></a></div> <center> <div class="background"> <div class="container"> <?php echo $return_content; ?> </div> </div> </center> </body> </html> But after I click submit, I get the "No database selected" error, but using WAMP, I include config.php which holds the following details: <?php $title = "NovaUpload - File Uploader"; mysql_connect("localhost", "", ""); mysql_select_db("data"); ?> And if functions.php is required, he <?php function AccountRelated($username, $password, $query_type) { if($query_type == 1) { $set_query = mysql_query("SELECT COUNT(d.username), u.date, u.username FROM uploads d, users u WHERE d.username = '$username' AND u.username = '$username' LIMIT 1") or die(mysql_error()); //user must not exist if(mysql_num_rows($set_query) == 0) { $content_return = 'Sorry, no information was found'; } else { $grab = mysql_fetch_assoc($set_query); //login information if($grab['COUNT(d.username)'] > 0) { $welcome_return = "You have uploaded ". $grab['COUNT(d.username)'] ." files. You've registered on ". $grab['u.date'] ."!"; } else { $welcome_return = "You have uploaded 0 files. You've registered on ".$grab['date'] . "!"; } } } elseif($query_type == 2) { $set_query = mysql_query("SELECT title,views,downloads,description,username,date FROM uploads LIMIT 20"); if(mysql_num_rows($set_query) == 0) { $content_return = "Sorry, there are currently no files uploaded to view."; } else { //display all files while($row = mysql_fetch_assoc($set_query) == 0) { echo $row['title']."<br/>"; } } } elseif($query_type == 3) { $username = mysql_real_escape_string($_POST['username']); $password = sha1(sha1(md5($_POST['password']))); if(!$username || !$password) { $return_content = "All fields are required! <table><form action='register.php' method='POST'> <tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr> <tr><td>Password</td><td><input type='text' name='password' maxlength='30'</td></tr> <tr><td><input type='submit' value='Register'></td></tr> </form></table>"; } else { $set_query = mysql_query("SELECT username FROM users WHERE username = '$username' LIMIT 1"); if(mysql_num_rows($set_query) == 0) { $return_content = "You have successfully registered the account ". $username ." with the password ". $_POST['password'] ."!"; mysql_query("INSERT INTO users VALUES (null, '$username', '$password', 0, 0, '". date("M-d-Y") ."', '". $_SERVER['REMOTE_ADDR'] ."')") or die(mysql_error()); } else { $return_content = "An account with this username already exists."; } } return $return_content; } else { //nothing to process } } ?> Hi, I'm trying to insert this $inceptiondate = date("Y-m-d 12:00:00"); to the database, the Y-m-d does make it to database, but the 12:00pm doesn't. Whenever it reaches the database, it becomes 00:00:00 Where did I got wrong? Thanks Hello.. I'm a somewhat beginner in php, but i decided to create my own basic forums system with a content managing system. Right now I'm trying to figure out how to make a thread link be at the top of the list for the forum display page, when someone posts a response or creates a new thread. HELP MUCH APPRECIATED What needs to be changed to make this work... Code: [Select] // Build query. $q2 = "UPDATE member SET logged_in=?, last_activity=time(), updated_on=NOW() WHERE id=? LIMIT 1"; Apparently PHP doesn't like time() Debbie This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310181.0 guys, please help i have table with datas like speed of vehicle, position e.t.c from morning 8 a.m. to 8 p.m. I need to get these details, but after every 15 minutes i.e. after selecting datas at 8 a.m. it shd select datas @ 8.15 a.m. then 8.30 a.m. hw can i write a mysql query for this ? or a PHP approach is appreciated I’m translating some mixed PHP/MySQL code into pure MySQL code. Now I'm having a problem about how to translate PHP's time() function. I’m not sure how to choose between NOW(), CURDATE(), CURTIME(), and several others. I tried NOW(), but to my surprise it outputs today’s year (i.e. 2014) instead of the Unix integer timestamp I'm looking for. And this behaviour seems contray to the MySQL manual. What should I do ? I have an ecommerce site on shared hosting enviroment. My ecommerce site stores customer data (name, address, email, phone, and item purchase) in mySQL database. (No super private data like credit card numbers or social security numbers.) Using openssl (openssl_cipher, iv, etc.), I've been encrypting this customer data and storing the encrypted data in mySQL. Today, I'm thinking "what's the point." It's like having a lockbox with the key on the wall above...
My thoughts: What do you all think? Sorry for my bad english. I am not from around these parts.
hi i have a mysql table with upddate and updtime field as follows: upddate updtime 2011-02-25 11:03:05 2011-01-28 08:01:09 2011-02-20 07:00:08 2011-02-15 06:10:02 2011-02-05 10:21:04 2011-02-09 10:20:25 the data types for upddate is mysql date and for updtime its mysql time In my php page i use Code: [Select] <?php echo $date = date("d M Y",strtotime($row_rs1['upddate'])); ?> to retrieve date and the results displays as 25 Feb 2011. And for time right now im using Code: [Select] <?php echo $row_rs1['updtime']; ?> which displays time as 11:03:05 I want to display time as HH:MM only, how can i do it? Code: [Select] $date = date('m-d-y'); $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO users VALUES ($username, $password, 0, $ip, $date)") or die(mysql_error()); Error: 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 '.60.116, 03-06-11)' at line 1 I'm not sure why I get this error. :/ Is there any way to have a field that will update any time its row is updated?
My situation is that I will have multiple devices writing to a database, and in one case the time that is being kept track of is important. And the devices writing to the database are a bit difficult to keep accurate times on, so instead of writing the time from the devices themselves, I was hoping I could just have a field update itself. I know it can be done on INSERT, but I do not want to do an INSERT every time.
Thanks!
Hello. I have a mysql database with an 'entrytime' field which contains the unix timestamp the record was added. How do I create a mysql query to select all records for a given month/year? For example, if I wanted to create a query to display all records for October 2010 how do I go about it? I am at a loss and can't find my answer via google. Thanks in advance for any help! How to output a MySQL timestamp field to correct local time with daylight saving with PHP?
Local time is set in php.ini with: date.timezone = "Europe/London"
Confirmed set with: <?php echo date_default_timezone_get(); ?>
But when I echo the timestamp field it does not display correct UK time for the record (an hour behind correct UK time).
<?php echo date('jS F Y - g:ia', strtotime($row['Date'])); ?>
|