PHP - How Do You Echo Date Functions On Certain Times Of The Day??
Hello fellow php friends, Im having abit of trouble trying to echo out a statement at certain times of the day.
for example how would you echo out 'Good Morning' between the times of 01am to 11.59am then echo out 'Good afternoon' between times of 12pm and 6pm and so on. Please help!!!!! Similar TutorialsHello all, I'm collecting date/time information via a form and would like to convert the info into something that I can stick in my MySql database (a timestamp???). I'm collecting the current month (variable name: month-- of the form "mm"), day (variable name: day -- of the form "dd"), year (variable name: year -- of the form "yyyy"), time of day (variable name: time -- of the form "h:00"), and before or after noon (variable name: ampm -- of the form "am" or "pm"). Any suggestions as to how to change this into a quantity that I can store as a value and then use to compare to other date/times would be appreciated. Thanks! Hello PHP Freaks, I am using a basic payment frame system, and it requires me to pass in a GMT time in this format, in a hidden form. "YYYYMMDDHHMMSS" I have found a lot of examples in PHP on how to format the above tag, but what would be the easiest way to generate it as is? To make things a little more complicated, there are different users in different GMT times, and based on the state they select it needs to + or - hours from the current time to get the GMT time. The formulas to calculate the results are as follows, just after the best approach in PHP to calculate: State #1: CURRENT_TIME + 10 HOURS = GMT TIME (echo as YYYYMMDDHHMMSS) and assign to $GMT_TIMESTAMP State #2: CURRENT TIME + 9.5 HOURS = GMT TIME (echo as YYYYMMDDHHMMSS) and assign to $GMT_TIMESTAMP What would be the best way to tackle this ? At the moment I have select boxes where the user can pick the state, then click SUBMIT. Thankyou in advance, D I have this script Code: [Select] <?php header("content-type: image/png"); include '../../api/config.php'; include "../../api/api.php"; $gamercard = getInfo($_GET['gamertag']); updateStats($gamercard['Gamertag'], "Nxe", 75); $type = $_GET['type']; switch ($type) { case "dark": $type = "dark.png"; break; case "light": $type = "light.png"; break; default: $type = "dark.png"; break; } $image = imagecreatefrompng("$type"); $img = imagecreatetruecolor(imagesx($image), imagesy($image)); $avatar_l = imagecreatefrompng($gamercard["Avatarpic-l"]); $avatar_body = imagecreatefrompng($gamercard["Avatarpic-body"]); imagecopy($img, $image, 0, 0, 0, 0, imagesx($image), imagesy($image)); imagecopy($img, $avatar_l, 64, 7, 0, 0, imagesx($avatar_l), imagesy($avatar_l)); imagecopy($img, $avatar_body, 175, -40, 0, 0, imagesx($avatar_body), imagesy($avatar_body)); for($i = 1; $i <=count($gamercard["RecentGames"]); $i++) { $gameimg = imagecreatefromjpeg($gamercard["RecentGames"][$i]["Icon"]); $x = ($i-1)*35 + 10; imagecopy($img, $gameimg, $x, 77, 0, 0, imagesx($gameimg), imagesy($gameimg)); } $ColorText = imagecolorallocate($img, 255, 255, 255); ImageTTFText($img, 10, 0, 10, 127, $ColorText, "font.ttf", $gamercard['Gamertag']); ImageTTFText($img, 10, 0, 135, 127, $ColorText, "font.ttf", $gamercard['Gamerscore']); imagepng($img); imagedestroy($img); ?> which is made to call the updateStats() function 1 time everytime the page loads. Heres the function (its in api.php) Code: [Select] function updateStats($gamertag, $type, $size) { $query = mysql_query("SELECT * FROM loadstats where Gamertag = '$gamertag' && Type = '$type'") or die(mysql_error()); $exists = mysql_num_rows($query); if ($exists == 0) { mysql_query("INSERT INTO loadstats (Gamertag, Type, Loads, Data) VALUES('$gamertag', '$type', '1', '$size' )") or die(mysql_error()); } else { $row = mysql_fetch_array($query); $newloads = $row['Loads'] + 1; $newdata = $row['Data'] + $size; mysql_query("UPDATE loadstats SET Loads = '$newloads' WHERE gamertag = '$gamertag' && Type = '$type'") or die(mysql_error()); mysql_query("UPDATE loadstats SET Data = '$newdata' WHERE gamertag = '$gamertag' && Type = '$type'") or die(mysql_error()); } } The wierd thing that is happening is, When i have the Header() set in the script, the updateStats() function appears to be called twice, but when the header is commented out, it is only called once. I can tell this by the change of data in the MYSQL database, the Loads value increases by 2 when the header is set, and it only creases by 1 when it isnt set. Any insight as to why this is happening would be greatly appreciated. My script reports the time with a six minute error added to the current time. I can't figure out why. I wrote a different script for solar calculation and get a 7 minute error subtracted. I'm hoping a response to this post will help me solve both problems. I abbreviated the six minute error script to simplify the problem. =====================================================
date_default_timezone_set("America/New_York"); ======================================================= Hi all What is the best way to work with times that are stored without there date but with only one date field regarding both times? Thanks Hello, all: I have been having these odd display stuff when I'm either trying to display or call functions or definitions. Seems like they work best when ALWAYS using echo to call them, though they also work without it?? So, what gives? when or how should I use them??? Should Definitions or Functions always be used along with ECHO?? as you can see slightly confused... EXAMPLE: // Why does this line work??? note, see here I'm using echo several times in order to display right) <?php if(RIGHT_COLUMN_WIDTH != '0') { echo "<td valign='top' width='" . RIGHT_COLUMN_WIDTH . "px'>"; echo categories(); echo "</td>";} ?> // But this one doesnt display just right?? Note: see echo not used when categories() function is called, but isnt it still being called by first echo?? <?php if(RIGHT_COLUMN_WIDTH != '0') { echo "<td valign='top' width='" . RIGHT_COLUMN_WIDTH . "px'>" . categories() . "</td>";} ?> Hello All New here and could use a bit of help. Basically I have 2 separate functions that echo their results out in an html page. My problem is the first function needs a value from the second function after it has run but needs to be echoed before the second for aesthetics. Here's a bit of code to explain. Code: [Select] <div class="bag"><br/><?php echo writeShoppingCart(); ?> </div> <div id="contents"> <?php echo showCart(); ?> </div> So basically to work correctly I need showCart to finishing before calling writeShoppingCart() I tried doing a redirect to the same page but it didn't like that. Is there another way around this that I'm not aware of? I suppose I could write a third function to get the value I need and call it before but I was hoping for a something a little cleaner. Cheers I am looking for a way to have my 'start_date', echo ('start_date' + 1 month). I am looking at the line that reads .... date("F Y",strtotime($row['start_date'])). Does anyone have a suggestion. The date format read, July 2014 or alphabetical full month, numerical full year. Thank you in advance.
<?php $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ echo "<tr> <td><a href='view_invoice.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>$row[meter_id]</a></td> <td>" . date("F Y",strtotime($row['start_date'])) . "<td>$row[invoice_no]</td><td>" . date_format($row['invoice_date'],'Y-m-d') . "<td>$row[amount_paid]</td>" . "<td>$row[payment_date]</td>" . "<td>$row[check_number]</td>" ;}sqlsrv_free_stmt($query); ?> Edited by Butterbean, 11 January 2015 - 08:19 PM. New user of PHP here! I'm using it to display entries from my MYSQL database. Image below. This is the code snippet that displays information from the 'name', 'author' and 'date' columns of my database. I learned this technique from w3schools. $result = mysql_query("SELECT * FROM levels ORDER BY date DESC"); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['author'] . "</td>"; echo "<td align='right'>" . $row['date'] . "</td>"; echo "</tr>"; } I would like to use the date() function to format the date differently. But the date() function requires that I convert my time into a timestamp. I know you have to use the mktime() function for this, but I don't know how. Can someone show me how to pass the contents from $row[date] into the mktime() function? Sorry for the topic title not explaining much, but I did not now how to word it! I was previous given some code at http://www.phpfreaks.com/forums/php-coding-help/streamlining-dreamweaver-generated-php-code/msg1459677/#msg1459677 that created a header every time a crtieria changed, in this case a players position. I have tried to tailor this to another page but have got it wrong somewhere. In this instance I was a change of date to be the determining factor. For example, with what I have tried so far, the output is 2011-04-02 Lowestoft Town v Tonbridge Angels 2011-04-02 Tooting & Mitcham United v Maidstone United 2011-04-02 Wealdstone v Concord Rangers 2011-04-09 Hastings United v Margate 2011-04-09 AFC Hornchurch v Carshalton Athletic 2011-04-09 Billericay Town v Aveley when I actually want 2011-04-02 Lowestoft Town v Tonbridge Angels Tooting & Mitcham United v Maidstone United Wealdstone v Concord Rangers 2011-04-09 AFC Hornchurch v Carshalton Athletic Billericay Town v Aveley I have tried to adjust the code to reflect the different query etc but something is missing. Thinking further ahead, there will also be a second criteria, in that games in different competitions could be played on the same day so I would also want to group the output by the competition ('comp' in the table) to get 2011-04-02 League Lowestoft Town v Tonbridge Angels Tooting & Mitcham United v Maidstone United Cup Wealdstone v Concord Rangers 2011-04-09 League AFC Hornchurch v Carshalton Athletic Cup Billericay Town v Aveley I would imagine that would just mean drilling down one more level in the code once I get this bit right. The tables, with a sample of data are Code: [Select] CREATE TABLE `all_games` ( `all_games_id` int(11) NOT NULL auto_increment, `date` date default NULL, `time` time default NULL, `comp` int(11) NOT NULL default '1', `round` tinyint(4) default NULL, `replay` char(1) default NULL, `home_team` int(11) NOT NULL default '1', `away_team` int(11) NOT NULL default '1', `home_goals` int(11) default NULL, `away_goals` int(11) default NULL, `home_ht` int(11) default NULL, `away_ht` int(11) default NULL, `attendance` int(11) default NULL, PRIMARY KEY (`all_games_id`) ) TYPE=MyISAM AUTO_INCREMENT=732 ; INSERT INTO `all_games` VALUES (700, '2011-04-23', '00:00:00', 1, NULL, '', 11, 20, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (701, '2011-04-23', '00:00:00', 1, NULL, '', 12, 13, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (702, '2011-04-23', '00:00:00', 1, NULL, '', 15, 22, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (703, '2011-04-23', '00:00:00', 1, NULL, '', 21, 7, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (704, '2011-04-25', '00:00:00', 1, NULL, '', 1, 14, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (705, '2011-04-25', '00:00:00', 1, NULL, '', 4, 6, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (706, '2011-04-25', '00:00:00', 1, NULL, '', 8, 15, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (707, '2011-04-25', '00:00:00', 1, NULL, '', 13, 2, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (708, '2011-04-25', '00:00:00', 1, NULL, '', 16, 21, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (709, '2011-04-25', '00:00:00', 1, NULL, '', 17, 3, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (710, '2011-04-25', '00:00:00', 1, NULL, '', 18, 9, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (711, '2011-04-25', '00:00:00', 1, NULL, '', 19, 5, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (712, '2011-04-25', '00:00:00', 1, NULL, '', 20, 12, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (713, '2011-04-25', '00:00:00', 1, NULL, '', 22, 11, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (714, '2011-04-30', '00:00:00', 1, NULL, '', 14, 18, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (715, '2011-04-30', '00:00:00', 1, NULL, '', 2, 19, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (716, '2011-04-30', '00:00:00', 1, NULL, '', 3, 22, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (717, '2011-04-30', '00:00:00', 1, NULL, '', 5, 13, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (718, '2011-04-30', '00:00:00', 1, NULL, '', 6, 8, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (719, '2011-04-30', '00:00:00', 1, NULL, '', 9, 17, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (720, '2011-04-30', '00:00:00', 1, NULL, '', 11, 7, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (721, '2011-04-30', '00:00:00', 1, NULL, '', 12, 1, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (722, '2011-04-30', '00:00:00', 1, NULL, '', 15, 20, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (723, '2011-04-30', '00:00:00', 1, NULL, '', 21, 4, NULL, NULL, NULL, NULL, NULL); CREATE TABLE `competitions` ( `comp_id` int(11) NOT NULL auto_increment, `comp_name` varchar(45) default NULL, `comp_short_name` varchar(4) default NULL, `logo` varchar(255) NOT NULL default '', PRIMARY KEY (`comp_id`) ) TYPE=MyISAM AUTO_INCREMENT=8 ; INSERT INTO `competitions` VALUES (1, 'Isthmian League Premier Division', 'ILP', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/tRymanLeague.png'); INSERT INTO `competitions` VALUES (2, 'FA Cup', 'FAC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/facup.png'); INSERT INTO `competitions` VALUES (3, 'FA Trophy', 'FAT', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/fattophy.png'); INSERT INTO `competitions` VALUES (4, 'Kent Senior Cup', 'KSC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/kentseniorcup.png'); INSERT INTO `competitions` VALUES (5, 'Isthmian League Cup', 'ILC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/isthmianleaguecup.png'); INSERT INTO `competitions` VALUES (6, 'Friendly', 'FR', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/friendly.png'); INSERT INTO `competitions` VALUES (7, 'Kent Messenger Cup', 'KMC', ''); CREATE TABLE `teams` ( `team_id` int(11) NOT NULL auto_increment, `team_name` varchar(45) default NULL, `short_name` varchar(5) default NULL, `badge` varchar(255) default NULL, `year_formed` int(11) default NULL, `nickname` varchar(255) default NULL, `previous_names` varchar(255) default NULL, `website` varchar(255) default NULL, `twitter` varchar(255) default NULL, `facebook` varchar(255) default NULL, `telephone_number` varchar(255) default NULL, `chairman` varchar(255) default NULL, `manager` varchar(255) default NULL, `home_colours` varchar(255) default NULL, `away_colours` varchar(255) default NULL, `stadium` int(11) default NULL, `2009/10` varchar(255) default NULL, PRIMARY KEY (`team_id`) ) TYPE=MyISAM AUTO_INCREMENT=74 ; INSERT INTO `teams` VALUES (1, 'Aveley', 'Ave', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/aveley.png', 1927, 'The Millers', 'None', 'http://www.aveleyfc.net/', NULL, NULL, '01708865940', 'Graham Gennings', 'Alan Kimble', 'Black & Blue/Blue/Blue', 'Black & White/White/White', 3, 'Isthmian League Premier Division, 3rd'); INSERT INTO `teams` VALUES (2, 'Billericay Town', 'Bill', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/billericaytown.png', 1880, 'Ricay, The Blues', 'None', 'http://www.billericaytownfc.co.uk/', 'http://twitter.com/BTFC', 'http://www.facebook.com/billericaytownfc', '01277652188', 'Steve Kent', 'Craig Edwards', 'Blue/White/Blue', 'White/Black/White', 2, 'Isthmian Premier, 13th'); INSERT INTO `teams` VALUES (3, 'Bury Town', 'Bur', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/burytown.png', 1872, 'The Blues', 'Bury St Edmunds, Bury United', 'http://www.burytownfc.co.uk', NULL, NULL, '01277999999', 'Russell Ward', 'Richard Wilkins', 'Blue & Red/Blue/Blue', 'White/Black/White', 10, 'Southern League Division One Midlands, 1st'); INSERT INTO `teams` VALUES (4, 'Canvey Island', 'Can', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/canveyisland.png', 1926, 'The Gulls', 'None', 'http://www.canveyislandfc.com', 'http://twitter.com/CIFC', NULL, NULL, 'George Frost', 'John Batch', 'Yellow/Blue/White', 'White/White/White', 11, 'Isthmian League Premier Division, 16th'); INSERT INTO `teams` VALUES (5, 'Carshalton Athletic', 'Car', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/carshaltonathletic.png', 1905, 'The Robins', 'Mill Lane Misson', 'http://www.carshaltonathletic.co.uk/', 'http://twitter.com/carshaltonath', NULL, '02086428658', 'Harry Driver', 'Mark Butler', 'Red/Red/Red', 'Maroon/White/Maroon', 9, 'Isthmian League Premier Division, 17th'); INSERT INTO `teams` VALUES (6, 'Concord Rangers', 'Con', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/concordrangers.png', 1967, 'Beach Boys', 'None', 'http://www.concordrangers.co.uk/', 'http://twitter.com/ConcordRangers', NULL, '01268691780', 'Antony Smith', 'Danny Scopes / Danny Cowley', 'Yellow/Blue/Blue', 'TBA', 12, NULL); INSERT INTO `teams` VALUES (7, 'Cray Wanderers', 'Cray', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/craywanderers.png', 1860, 'The Wands', 'None', 'http://www.craywands.co.uk', 'http://twitter.com/craywanderers', NULL, '02084605291', 'Gary Hillman', 'Ian Jenkins', 'Amber/Black/Amber', 'Blue/White/White', 13, 'Isthmian League Premier Division, 15th'); INSERT INTO `teams` VALUES (8, 'Croydon Athletic', 'Croy', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/croydonathletic.png', 1986, 'The Rams', 'Wandsworth & Norwood', 'http://croydonathletic.net', NULL, NULL, '0208664834', 'TBA', 'Dave Garland & Bob Langford', 'Maroon & White/Maroon/Maroon', 'Yellow/Blue/Blue', 14, 'Isthmian League Division One South, 1st'); INSERT INTO `teams` VALUES (9, 'Folkestone Invicta', 'Fol', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/folkestoneinvicta.png', 1936, 'Invicta, The Seasiders', 'None', 'http://www.folkestoneinvicta.co.uk/', 'http://twitter.com/FIFC', NULL, '01303257461', 'TBA', 'Neil Cugley', 'Amber/Black/Amber', 'Red/White/Red', 15, 'Isthmian League Division One South, 2nd'); INSERT INTO `teams` VALUES (10, 'Grays Athletic', 'Gra', 'N/A', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); INSERT INTO `teams` VALUES (11, 'Harrow Borough', 'Har', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/harrowborough.png', 1933, 'The Boro, The Reds', 'Roxoinian, Harrow Town', 'http://www.harrowboro.com/', 'http://twitter.com/harrowboro_fc', NULL, '08706091959', 'Peter Rogers', 'David Howell', 'Red/Red/Red', 'White/White/Black', 16, 'Isthmian League Premier Division, 14th'); INSERT INTO `teams` VALUES (12, 'Hastings United', 'Has', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/hastingsunited.png', 1894, 'The Arrows, The U''s', 'Hastings Town, Hastings & St. Leonards', 'http://www.hastingsunitedfc.co.uk/', 'http://twitter.com/hastingsufc', NULL, '01424444635', 'David Walter', 'Tony Dolby', 'Maroon/Maroon/Maroon', 'White/White/White', 17, 'Isthmian League Premier Division, 7th'); INSERT INTO `teams` VALUES (13, 'Hendon', 'Hen', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/hendon.png', 1908, 'The Greens, The Dons', 'Christ Church Hampstead, Hampstead Town, Hampstead, Golders Green', 'http://www.hendonfc.net/', 'http://twitter.com/HendonFC', NULL, '02089083553', 'TBA', 'Gary McCann', 'Green/Green/Green', 'Blue/Blue/Blue', 18, 'Isthmian League Premier Division, 10th'); INSERT INTO `teams` VALUES (14, 'AFC Hornchurch', 'AFC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/afchornchurch.png', 1923, 'The Urchins', 'Upminster Wanderers, Hornchurch & Upminster', 'http://www.afchornchurch.com/', 'http://twitter.com/AFCHornchurch', 'http://www.facebook.com/AFCHornchurch', '01708220080', 'TBA', 'Colin McBride', 'Red & White/Black/Red', 'Blue & White/Blue/Blue', 1, 'Isthmian League Premier Division, 9th'); INSERT INTO `teams` VALUES (15, 'Horsham', 'Hor', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/horsham.png', 1871, 'The Hornets', 'None', 'http://www.hornetsreview.co.uk/', NULL, NULL, '01403266888', 'Kevin Borrett', 'John Maggs', 'Yellow & Green/Yellow/Yellow', 'Blue/Black/White', 19, 'Isthmian League Premier Division,11th'); The query is $all_games = mysql_query("SELECT *, HT.team_name as HomeTeam, VT.team_name as AwayTeam, COMP.comp_short_name as CP FROM all_games JOIN teams as HT ON all_games.home_team = HT.team_id JOIN teams as VT ON all_games.away_team = VT.team_id JOIN competitions as COMP ON all_games.comp = COMP.comp_id ORDER BY date ASC "); if (!$all_games) { die("Query to show fields from table failed"); And the code that echoes the right values, but does not seperate the the dates is if($all_games) { if(mysql_num_rows($all_games)) { $lastdate = 0; while ($row_all_games = mysql_fetch_assoc($all_games)) { // when the date changes output a new heading if($lastdate = $row_all_games['date']) { echo "<h1>".strtoupper($row_all_games['date'])."</h1>"; $lastdate = $row_all_games['date']; } echo $row_all_games['HomeTeam']." v ".$row_all_games['AwayTeam']; } } else { echo "No results!"; } } I must admit that I have tried a few variations but the nearest I have got is for the page to echo "No results!" I may be a fraction off getting it right or a million miles away so if anyone can give any pointers I will be very grateful. Thanks in advance Steve Here is the code im using $dateOfBirth = ''; preg_match('|Born on ([a-zA-Z]*\s[0-9]*,\s[0-9]*)\\\u003c\\\/span>|', $page, $match); if($match && count($match)>0) { $date = str_replace(",","",$match[1]); blue($date); $timestamp = strtotime($date); $dateOfBirth = date('Y-m-d',$timestamp); // 1994-03-23 } else { red("No Age is set on profile"); continue; } im getting a match like this March 9, 1993 When i run my script im getting this error [2048] strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead Error: [2048] date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead What could be the problem?? I'm using microtime to capture $start_time and $finish_time bothing using microtime() function. I then pass both $start_time and $finish_time into date() function to parse a date. The difference between $start_time and $finish_time is also calculated. The problem being the date() function is producing incorrect values. list($total_count, $success_count, $errors_data, $start_time, $finish_time) = $summary_data; $duration_time = $finish_time - $start_time; echo "<b>Started Processing At:</b> ".date('m/d/Y H:i:m', $start_time)."<br/>"; echo "<b>Completed Processing At:</b> ".date('m/d/Y H:i:m', $finish_time)."<br/>"; echo "<b>Processing Duration:</b> $duration_time seconds<br/><br/>"; The output: Started Processing At: 11/22/2010 18:45:11 Completed Processing At: 11/22/2010 18:45:11 Processing Duration: 8.0499620437622 seconds What I'm basically trying to accomplish is, that the datetime of the user posted information is registered with the Now() function in the query, BUT that the user entered information gets echo'd out with the Date showing ONLY. What I have is this: -Just as an example- INSERT INTO db (date_created) VALUES (now()) while ($row = mysqli_fetch_array($data)) { echo '<tr><td>' . $row['date_created'] . '</td></tr>'; } mysqli_close($dbc); With this way of course I get Date and Time showcased just like it's inserted into the DB. What would be a legit way of showcasing just date. Thanks for help. EDIT: or is there a better way than using now() to showcase the date when the user entered information was posted? Here is one part of php code. Here I try to show in last 1 month which dates exactly user made orders. When I run the SQL code in command prompt it works. I think problem is in while loop. Thanks beforhand for contribution. $query = "SELECT Date FROM orders WHERE User='$username' and DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Date;"; $result = mysql_query($query,$link_id) or die (mysql_error()); echo "<table border='1'> <tr> <td> Last 1 month's orders:</td> </tr>"; while($order_date = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>" . $order_date[0] . "</td>"; echo "</tr>"; } echo "</table> Hello, I want to display a weekly events day and time. This event will always be on Saturday @ 10:45 am however, I want to output: 2011-09-17 10:45 then when that date is passed - I want it to change to the next Saturday: 2011-09-21 10:45 etc. Any ideas? OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> I have a script I am putting together that simulate a cricket game. The only issue is, that there are a huge number of functions because there doesn't seem to be any other way to do this properly. As well as this, there a while() loop and all this seems to be leading to the page reaching a max 30 second timeout when generating the result. My code is attached below, it is quite messy at the moment because i've just be working on it, but I was wondering if anyone has any solutions of how I can speed this up or change to prevent a timeout: <?php // Error reporting error_reporting(E_ALL); // Connect DB mysql_connect("wickettowicket.adminfuel.com", "rockinaway", "preetha6488") or die(mysql_error()); // Select DB mysql_select_db("wickettowicket") or die(mysql_error()); // MySQL queries to find batsmen and bowlers $array_batsmen = mysql_query('SELECT id, name, ability, strength FROM wtw_players WHERE team_id = 1 ORDER BY id ASC'); $array_bowlers = mysql_query('SELECT id, name, ability, strength FROM wtw_players WHERE team_id = 2'); // Start table for data $data = '<table width="600px">'; // Create blank scorecard while ($array_bat = mysql_fetch_array($array_batsmen)) { $data .= '<tr><td>'.$array_bat['name'].'</td><td></td><td></td><td>0</td></tr>'; } // Set up arrays for players $current_batsman = $current_bowler = array(); // Reset query mysql_data_seek($array_batsmen,0); $in_one = $in_two = $it = ''; function currentBatsman($id, $name, $ability, $strength, $out, $in, $runs) { global $current_batsman; $current_batsman = array ( 'id' => $id, 'name' => $name, 'ability' => $ability, 'strength' => $strength, 'out' => $out, 'in' => $in, 'runs' => $runs ); echo 'set current'; } // Set up arrays of batsmen while ($array = mysql_fetch_array($array_batsmen)) { if ($it < 3 && $in_one == '') { currentBatsman($array['id'], $array['name'], $array['ability'], $array['strength'], 0, 1, 0); $batsmen[$array['id']] = array ( 'id' => $array['id'], 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'], 'out' => 0, 'in' => 1, 'runs' => 0 ); $in_one = $array['id']; $current = $array['id']; $it++; } else if ($it < 3 && $in_two == '') { $batsmen[$array['id']] = array ( 'id' => $array['id'], 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'], 'out' => 0, 'in' => 1, 'runs' => 0 ); $in_two = $array['id']; $it++; } else { $batsmen[$array['id']] = array ( 'id' => $array['id'], 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'], 'out' => 0, 'in' => 0, 'runs' => 0 ); } } // Bowler Array while ($array = mysql_fetch_array($array_bowlers)) { $bowlers[] = array ( 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'] ); } // Reset both queries mysql_data_seek($array_bowlers,0); mysql_data_seek($array_batsmen,0); function changeBatsman($just_out) { global $array_batsmen, $batsmen; //Update array $batsmen[$just_out] = array ( 'in' => 1, 'out' => 1 ); while ($array = mysql_fetch_array($array_batsmen)) { if ($just_out != $array['id'] && $batsmen[$array['id']]['out'] != 0) currentBatsman($array['id'], $array['name'], $array['ability'], $array['strength'], 0, 1, 0); } // Reset query mysql_data_seek($array_batsmen,0); echo 'change batsman'; } function swapBatsman($other_batsman) { global $array_batsmen, $batsman; while ($array = mysql_fetch_array($array_batsmen)) { if ($other_batsman != $array['id'] && $batsman[$array['id']]['out'] != 0 && $batsman[$array['id']]['in'] == 1) currentBatsman($array['id'], $array['name'], $array['ability'], $array['strength'], 0, 1, 0); } // Reset query mysql_data_seek($array_batsmen,0); echo 'swap batsman'; } $runs = $outs = $balls = $overs = 0; $played = array(); function selectBowler() { global $bowlers, $current_bowler; // Select random bowler $choose_bowler = array_rand($bowlers, 1); $current_bowler = array ( 'name' => $bowlers[$choose_bowler]['name'], 'ability' => $bowlers[$choose_bowler]['ability'], 'strength' => $bowlers[$choose_bowler]['strength'] ); } /* function selectBatsman(); { global $array_batsmen; while ($array_batsmen[]['out'] != 1) { }*/ function bowl() { global $batsmen, $bowlers, $current_bowler, $current_batsman, $data, $balls, $outs, $runs; if ($current_batsman['out'] == 0) { echo 'bowling'; // Set the initial number $number = rand(0, 190); // Ability of batsman if ($current_batsman['ability'] > 90) $number += 30; else if ($current_batsman['ability'] > 70) $number += 15; else if ($current_batsman['ability'] > 50) $number += 2; else $number = $number; // Strength of batsman if ($current_batsman['strength'] > 90) $number += 15; else if ($current_batsman['strength'] > 70) $number += 10; else if ($current_batsman['strength'] > 50) $number += 5; else $number = $number; // Depending on overs if ($balls > 270) $number += 30; else if ($balls > 120) $number -= 10; // Ability if ($current_bowler['ability'] > 90) $number -= 30; else if ($current_bowler['ability'] > 70) $number -= 15; else if ($current_bowler['ability'] > 50) $number -= 2; else $number = $number; // If batsman has made a huge total of runs, we need to knock some numbers off - more likely to get out if ($current_batsman['runs'] > 200) $number -= 70; else if ($current_batsman['runs'] > 100) $number -= 30; // Finally sort out runs if ($number > 190) $run = 6; else if ($number > 170) $run = 4; else if ($number > 160) $run = 3; else if ($number > 100) $run = 2; else if ($number > 50) $run = 1; else if ($number > 10) $run = 0; else if ($balls > 120 && $number > 0) $run = 0; else $run = -1; // Increase number of balls $balls += 1; // Are they out? if ($run == -1) { $current_batsman['out'] = 1; $played[] = $current_batsman['id']; $find = '<tr><td>'.$current_batsman['name'].'</td><td></td><td></td><td>0</td></tr>'; $replace = '<tr><td>'.$current_batsman['name'].'</td><td></td><td>'.$current_bowler['name'].'</td><td>'.$current_batsman['runs'].'</td></tr>'; $data = str_replace($find, $replace, $data); changeBatsman($current_batsman['id']); echo 'out'; } else { $current_batsman['runs'] += $run; $runs += $run; if ($run == 1 || $run == 3) { swapBatsman($current_batsman['id']); echo 'time to swap'; } echo $run; } // Count outs if ($current_batsman['out'] == 1) $outs += 1; } } function game() { global $main, $batsmen, $bowlers, $data, $batted, $balls, $outs, $current_batsman; // Check if possible while ($balls <= 295 && $outs < 10) { selectBowler(); // Actually bowl now bowl(); } } game(); echo $data; Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> I teaching myself php, but I am coming from java and other compiled languages, so the process has been a little bumpy. I am trying to do something like this: Code: [Select] class my_class { function one () { $two = two (); $three = three (); $five = $two + $three; return $five; } function two () { $two = 2; return $two; } function three () { $three = 3; return $three; } } Unfortunately, I keep getting an error message saying that my call to two () is an undefined function. I am gathering from this that the scope of one () is not aware of the existence of two (). Is there a way to get around this so I can call two () and three () from one ()? |