-
Posts
276 -
Joined
-
Last visited
Posts posted by will35010
-
-
Does anybody know how to modify my script? I'm not looking to replace my script. I want to change my script is all.
-
Doesn't really seem like a very efficient 'time ago' script.
You can find a few alternatives on this page:
http://php.net/manual/en/function.time.php
Search for 'ago'
This one seems to be pretty good though:
http://aidanlister.com/2004/04/making-time-periods-readable/
This would be a proper way of using it:
function getTIME($time) { $convert = time( ) - $time; return time_duration($convert); }
You could also tweak your own script to fit for this, but I wouldn't really recommend it because it's rudementary. You'd need to round ( ) them to the nearest integer.
My script already does that.
-
You're looking for this: http://ca.php.net/manual/en/function.round.php
Fixed that. Thanks!
updated code
//function to calculate time duration using timestamps function getTIME($time) { //start/end dates $startdate = $time; $enddate = time(); //difference between the two in seconds $time_period = ( $enddate - $startdate ); $minutes=floor($time_period/60); $hours=floor($minutes/60); $days=floor($hours/24); if($hours>=24) { $daysdisplay = round($hours/24); } if($hours==1) { $hoursdisplay=$hours; } if(($minutes%60) > 1) { $minutesdisplay=($minutes%60); } else if(($minutes%60)==1) { $minutesdisplay=($minutes%60); } else { $minutesdisplay=""; } $display=$daysdisplay."Day(s)& ".$hours."Hour(s) & ".$minutesdisplay." Mins"; return $display; }
-
I have this function that calculates time between two timestamps. I want it to display days and subtract that time from the hours. Example output would be 2 Day(s) & 3 Hour(s) & 43 Minutes
Right now it displays the days, but it displays it like 7.33333. I don't want anything past the decimal point and it also doesn't take away from the hour count.
//function to calculate time duration using timestamps function getTIME($time) { //start/end dates $startdate = $time; $enddate = time(); //difference between the two in seconds $time_period = ( $enddate - $startdate ); $minutes=floor($time_period/60); $hours=floor($minutes/60); $days=floor($hours/24); if($hours>=24) { $daysdisplay = ($hours/24); } if($hours==1) { $hoursdisplay=$hours; } if(($minutes%60) > 1) { $minutesdisplay=($minutes%60); } else if(($minutes%60)==1) { $minutesdisplay=($minutes%60); } else { $minutesdisplay=""; } $display=$daysdisplay."Day(s)& ".$hours."Hour(s) & ".$minutesdisplay." Mins"; return $display; }
-
SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND ((FROM_UNIXTIME(event_time) BETWEEN '$startdate' AND '$enddate') OR FROM_UNIXTIME(event_time) = '$startdate');
or
SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND FROM_UNIXTIME(event_time) >= '$startdate' AND FROM_UNIXTIME(event_time) <= '$enddate');
Second query had an error. First query returned 0 for a single day picked. I think I'm just going to change my db to use date/time. It seems easier...lol. Thanks anyway.
-
I'm using this query to return a count:
SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND FROM_UNIXTIME(event_time) BETWEEN '$startdate' AND '$enddate';
It works fine unless the user selects the same date. the user has to select the day before and the day after the day that they actually want data for. How can I fix that?
The date is being passed in YYYY-MM-DD format.
-
If you use the query I posted (adding event = 'Registration' AND to the WHERE clause), for the data you posted it returns 3 morning and 1 night result.
Thank you!
-
This SELECT * FROM `event` WHERE event = 'Registration'
produces:
eventid patientid visitid event event_time username
21 0 3 Registration 1280759616 will
31 20 6 Registration 1280736699 will
22 18 4 Registration 1280760522 will
29 19 5 Registration 1280769567 will
-
Someone already posted how to make the query that I posted work with a Unix Timestamp -
SELECT sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '06:00:00' AND '11:59:59' THEN 1 END) AS morning , sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '12:00:00' AND '17:59:59' THEN 1 END) AS afternoon , sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '18:00:00' AND '23:59:59' THEN 1 END) AS evening , sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '00:00:00' AND '05:59:59' THEN 1 END) AS night FROM your_table WHERE FROM_UNIXTIME(event_time) BETWEEN '2010-07-01 00:00:00' AND '2010-08-05 23:59:59';
I tried this and it still returned nulls:
SELECT sum(CASE WHEN TIME(event_time) BETWEEN '06:00:00' AND '11:59:59' THEN 1 END) AS morning , sum(CASE WHEN TIME(event_time) BETWEEN '12:00:00' AND '17:59:59' THEN 1 END) AS afternoon , sum(CASE WHEN TIME(event_time) BETWEEN '18:00:00' AND '23:59:59' THEN 1 END) AS evening , sum(CASE WHEN TIME(event_time) BETWEEN '00:00:00' AND '05:59:59' THEN 1 END) AS night FROM event WHERE event = 'Registration' AND event_time >= unix_timestamp('2010-07-06') and event_time <= unix_timestamp('2010-08-06')
-
If your data was stored as a mysql datetime or mysql timestamp (not to be confused with a Unix Timestamp), the following query does what you are after -
SELECT sum(CASE WHEN TIME(date_time) BETWEEN '06:00:00' AND '11:59:59' THEN 1 END) AS morning , sum(CASE WHEN TIME(date_time) BETWEEN '12:00:00' AND '17:59:59' THEN 1 END) AS afternoon , sum(CASE WHEN TIME(date_time) BETWEEN '18:00:00' AND '23:59:59' THEN 1 END) AS evening , sum(CASE WHEN TIME(date_time) BETWEEN '00:00:00' AND '05:59:59' THEN 1 END) AS night FROM your_table WHERE date_time BETWEEN '2010-07-01 00:00:00' AND '2010-08-05 23:59:59';
You could use the mysql FROM_UNIXTIME() function to get your Unix Timestamps onto DATETIME values in the query.
I tried your query but it returns null in each field. I place the timestamp into the database by using time() so I think that's a unix timestamp.
-
On your html, set the name for the checkboxes the same and the value something unique. Then you only have to check one.
So if the user selects 10 out of the 50 checkboxes will all the same name im not sure how I can take the selected data and input it into the database for example if checked update table users feild admin and make it 1.
I see what your saying, but I'd really have to see your code. It really depends on how it's written to see how to do it.
-
I know this but the problem is there will be like 50 records with 50 checkboxs so how can I define all 50 of them
On your html, set the name for the checkboxes the same and the value something unique. Then you only have to check one.
-
I don't understand how to apply the code you provided. I set $Openme as the var. I still don't understand how to check the url for CiFrame or use a default value if CiFrame is not specified in the url. Here is what i tried next, however it did not work. Any ideas?
<?php
if (isset ($_GET['CiFrame']))
$Openme = 'CiFrame';
else
$Openme = '/NonMembersFeatured.php';
?>
Iframe Code
<iframe name="CiFrame" width="727" height="805" src="<?php $Openme ?>" scrolling="auto" frameborder="0"></iframe>
Thank You
that should be:
<?php if (isset ($_GET['CiFrame'])) $Openme = $_GET['CiFrame']; else $Openme = '/NonMembersFeatured.php'; ?>
-
-
Does the count for the 4 time periods accumulate for each day in the date range or is the count for the 4 time periods kept separate for each day in the date range?
Accumulate. Example ten events were morning over a ten day period and five were afternoon over the same ten day period.
The end goal is to get it to display something like this:
/** echo "<table width='50%' border='0'> <tr> <td bgcolor='#d3d3d3'><div align='center'>Morning (6am-12pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Afternoon (12pm-6pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Evening (6pm-12am)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Night (12am-6am)</div></td> </tr>"; echo "<tr> <td><div align='center'>20</div></td> <td><div align='center'>10</div></td> <td><div align='center'>50</div></td> <td><div align='center'>5</div></td> </tr>"; echo "</table>"; **/
-
Does the count for the 4 time periods accumulate for each day in the date range or is the count for the 4 time periods kept separate for each day in the date range?
Accumulate. Example ten events were morning over a ten day period and five were afternoon over the same ten day period.
-
You don't say if the timestamps are unix timestamps. If they are and you wanted the number between 6AM and 12PM today the sql would be:
"select count(*) from event where event_time >= unix_timestamp('2010-08-06 06:00:00') and event time <= unix_timestamp('2010-08-06 12:00:00')
I was going to originally do it this way but the problem is the the date range is further than one day. And I need a separate count for each time period.
-
If you revisit your last thread about your code, you will find that your $enddate1 = strtotime($enddate."11:59:59"); ... calculations are not producing the value you think they are.
$enddate is the next day, so that is actually finding everything up to noon the next day, not the current day.
Thanks! I saw that as well. How do I parse the data to get a count of the timestamps in different times?
Updated Code:
<?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); //function to show date and time based on timestamp function showTIME($timestamp){ $date = date('F j Y h:i:s A', $timestamp); return $date; } $startdate = strtotime("2010-07-01"); $enddate = strtotime("2010-08-05"); //query to pull time stamps in between dates //convert dates into timestamp //$startdate = strtotime($_POST['startdate']); //$enddate = strtotime($_POST['enddate']); $sql = mysqli_query($conn, "SELECT event_time FROM event WHERE event = 'Registration' AND event_time BETWEEN '$startdate' AND '$enddate'"); while($row = mysqli_fetch_array($sql)){ $time = date('F j Y h:i:s A', $row['event_time']); } ?>
-
I need some help. I have this script that pulls timestamps from the database. What I want to do is create a count of how many of those timestamps that were returned were from the morning(6am-12pm), Afternoon (12pm-6pm), Evening (6pm-12am), or Night (12am-6am). How do I do I parse the timestamps to do that and display the count. Thanks!
<?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); //function to show date and time based on timestamp function showTIME($timestamp){ $date = date('F j Y h:i:s A', $timestamp); return $date; } $startdate = "2010-07-01"; $enddate = "2010-08-05"; //query to pull time stamps in between dates //convert dates into timestamp //$startdate = strtotime($_POST['startdate']); //$enddate = strtotime($_POST['enddate']); //convert dates into morning timestamp $startdate1 = strtotime($startdate."06:00:00"); $enddate1 = strtotime($enddate."11:59:59"); $sql = mysqli_query($conn, "SELECT event_time FROM event WHERE event = 'Registration' AND event_time BETWEEN '$startdate1' AND '$enddate1'"); while($row = mysqli_fetch_array($sql)){ echo showTIME($row['event_time'])."<br>"; } ?>
-
I just figured out the problem. It's returning exactly what I asked. I'm not parsing the data and converting that into a count.
-
I wrote this script to query the database and get the count between timestamps. I'm using strtotime to convert the user selected date and the pre-selected times into a usable timestamp to search with. I've echo the first one to ensure that it's creating the correct timestamp with time and it is. The problem is that it's returning data that's outside of the time. I don't know if it's my php or mysql, so I was hoping one of you could help. Thanks!
<?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); $startdate = "2010-07-01"; $enddate = "2010-08-05"; echo "Start Date: ".$startdate."<br>"; echo "End Date: ".$enddate."<br>"; //convert dates into timestamp $startdate1 = strtotime($startdate."00:00:00"); $enddate1 = strtotime($enddate."11:59:59"); echo "Start Date 1: ".$startdate1."<br>"; echo "End Date 1: ".$enddate1."<br>"; //convert dates into morning timestamp $startdate1 = strtotime($startdate."06:00:00"); $enddate1 = strtotime($enddate."11:59:59"); $sql = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate1' AND '$enddate1'"); $row = mysqli_fetch_array($sql); //convert dates into afternoon timestamp $startdate2 = strtotime($startdate."12:00:00"); $enddate2 = strtotime($enddate."17:59:59"); $sql1 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate2' AND '$enddate2'"); $row1 = mysqli_fetch_array($sql1); //convert dates into Evening timestamp $startdate3 = strtotime($startdate."18:00:00"); $enddate3 = strtotime($enddate."23:59:59"); $sql2 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate3' AND '$enddate3'"); $row2 = mysqli_fetch_array($sql2); //convert dates into night timestamp $startdate4 = strtotime($startdate."00:00:00"); $enddate4 = strtotime($enddate."05:59:59"); $sql3 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate4' AND '$enddate4'"); $row3 = mysqli_fetch_array($sql3); echo "<table width='50%' border='0'> <tr> <td bgcolor='#d3d3d3'><div align='center'>Morning (6am-12pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Afternoon (12pm-6pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Evening (6pm-12am)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Night (12am-6am)</div></td> </tr>"; echo "<tr> <td><div align='center'>".$row['COUNT(event_time)']."</div></td> <td><div align='center'>".$row1['COUNT(event_time)']."</div></td> <td><div align='center'>".$row2['COUNT(event_time)']."</div></td> <td><div align='center'>".$row3['COUNT(event_time)']."</div></td> </tr>"; echo "</table>"; ?>
-
Thank you for actually reading my question. Your solution worked. Thanks!!!
You can use a left join and then in the where clause specify that the value for the column in the visit_data table is null
SELECT *
FROM `rooms`
LEFT JOIN visit_data ON rooms.room = visit_data.room
WHERE visit_data.room IS NULL
-
Do you know the name you are looking for?
If so, just use an if loop:
http://w3schools.com/PHP/php_if_else.asp
Something like:
if($_SESSION['USERNAME'] == "John"{ then do something here }
-
I'm trying to create a select query that returns a list of rooms that aren't being used. I need help creating a query that shows me the rooms.room that aren't being used in visit_data.room. When a room is being occupied, my script puts the value from rooms.room into visit_data.room.
Any help would be greatly appreciated!!!
-- -- Table structure for table `rooms` -- CREATE TABLE IF NOT EXISTS `rooms` ( `id` int(11) NOT NULL AUTO_INCREMENT, `areaid` varchar(50) NOT NULL, `room` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ; INSERT INTO `rooms` (`id`, `areaid`, `room`) VALUES (1, 'ED', 'TA'), (7, 'ED', 'TB'), (9, 'ED', 'T2'); -- -- Table structure for table `visit_data` -- CREATE TABLE IF NOT EXISTS `visit_data` ( `visitid` int(11) NOT NULL AUTO_INCREMENT, `patientid` varchar(45) NOT NULL, `priority` varchar(100) NOT NULL, `alert1` varchar(100) DEFAULT '1', `alert2` varchar(100) DEFAULT '1', `alert3` varchar(100) DEFAULT '1', `cc` varchar(50) NOT NULL, `walkout` varchar(3) DEFAULT NULL, `areaid` varchar(45) NOT NULL, `room` varchar(45) DEFAULT NULL, `current_status` varchar(45) DEFAULT NULL, `doctor` varchar(50) DEFAULT NULL, `nurse` varchar(50) DEFAULT NULL, `reg_time` varchar(12) DEFAULT NULL, `discharged` varchar(45) DEFAULT NULL, `discharged_time` varchar(12) DEFAULT NULL, `disposition` varchar(100) DEFAULT NULL, PRIMARY KEY (`visitid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
function help
in PHP Coding Help
Posted
I didn't double post.
Don't waste your time since you can't help anyway. If I wanted to replace it, I would have just ran to Google and copied someone's code. I wanted to fix my code so I could learn from it. Forgive me for trying to actually learn vs. copying someone's code that I didn't write.