PHP - Diffrence Betwean Times Ignore Day Change
hello guys
i have 2 time variables
$time1 = 22:00;
$time2 = 03:00;
my $current_time is 01:00
how can i figure that $current_time is betwean the $time1 and $time2
the
if ($current_time > $time1 && $current_time < $time2)
works if the day not change!
is any way to ignore the day change
thanks
Edited by lioslios, 09 November 2014 - 10:07 PM. Similar Tutorialshey days im trying to get the differnce between the two dates but Code: [Select] $start_date = new DateTime($start_date); $todays_date = new DateTime("now"); $interval = $start_date->diff($todays_date); echo $interval->format('%R%a days'); but the error im getting is Fatal error: Call to undefined method DateTime::diff() i dont see what im doing wrong if someone could help please thank you Hello 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! Hi all. How can i see all the difference between two dates in a column. I know to see a single date difference we can do: $stmt = $pdo->query("SELECT DATEDIFF(date_paid, next_due) AS diffdate FROM table_name"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo $row['diffdate']; } but i want all the difference to show in a table along with other details. thanks Hi I have two filed in database storing time like this 19:00 and other 06:00 i need to get difference between both which is 13 hours. Thanks Hi all, I have a simple html form, when the values are posted to the php page I want to be able to bring up particular products based on specific details. However if the user does not enter a value, I want the script below to ignore that particular field and show all the results not taking in to consideration that field. Hope you understand. I was thinking maybe I could use something like if $_POST == "" IGNORE!! but I can not find an example on the internet. The script I have made so far is below. <?php $sql = "SELECT * FROM sales WHERE category='$_POST[category]' AND manufacturer='$_POST[manufacturer]' AND model='$_POST[model]' AND purchasetype='$_POST[type]'"; // IF VALUE OF SAY MODEL IS LEFT BLANK - I WANT THE PHP TO INGORE THE TYPE OF MODEL AND SHOW THE RESULTS JUST INCLUDING THE OTHER FIELDS. $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); $num = mysqli_num_rows($result); if ($num >0) // Login Name found { while($row = mysqli_fetch_assoc($result)) { ?> How can I ignore - when doing claculations? e.g. 150 - 50 = 100 150 - 225 = -75 // I WANT to display only 75 and ignore the - sign EDIT: I solved it! I have the following Query: Code: [Select] $query = "INSERT INTO characters SET psalt = '" .$salt. "'"; However, when the salt is generated, it may contain a ', thus stopping the Query. I need to know how I could make it so the Query would be unaffected by the ' in the salt value. Thanks! im trying to insert $myusername into a table only if $myusername does not exist is best to call the insert ignore or is there better way of doing this? also trying to make a list of logged in users which is allways updating when the page is auto refreshed whats the best to go about checking if the users is still there. i have a script that calls for a field, but if you arent on a blackberry it asks you to select a name first, so it gives error until you select: Notice: Undefined variable: posteid in E:\Website\citycore\2\mobile\schedule.php on line 20 i could make it so it didnt call for $posteid until after the name is selected, but then it wont work from the blackberry as it detects the pin number first. I have a pspell script and I want it to ignore upper case. ie at the moment if I check spelling for say christopher it returns spelling error of Christopher (upper case C) <?php $query = 'helllo'; $pspell_config = pspell_config_create("en"); pspell_config_ignore($pspell_config, 5); pspell_config_mode($pspell_config, PSPELL_FAST); pspell_config_personal($pspell_config, "/home/*/public_html/custom.pws"); pspell_config_repl($pspell_config, "/home/*/public_html/custom.repl"); $pspell_link = pspell_new_config($pspell_config); $words = preg_split ("/\s+/", $query); $ii = count($words); global $spellchecked; $spellchecked = ""; for($i=0;$i<$ii;$i++){ if (pspell_check($pspell_link, $words[$i])) { $spellchecked .= $words[$i]." "; } else { $erroneous = "yes"; $suggestions = pspell_suggest($pspell_link, $words[$i]); $spellchecked .= $suggestions[0]." "; } } if($erroneous == "yes") { $spellchecked2 = str_replace(" ", "+", $spellchecked); echo "Did you mean: <a href=GetSearchResults.php?Query=$spellchecked2&catID=&siteID=3><i>".$spellchecked."</a></i>?"; } else { echo $spellchecked . " is a valid word/phrase"; } ?> Below is some code I have that I would like to connect to databases that reside on different physical machines. The problem I can't seem to solve is how to ignore machines that are unreachable. Code: [Select] <html> <head> </head> <body> <?php $mysql_conn=new mysqli('192.168.1.67','admin','password','monkey'); $result=$mysql_conn->query("SELECT * from testtable"); echo "<table>"; echo "<th>Test Query</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['test1']; echo "</td></tr>"; } echo "</table>"; $mysql_conn=new mysqli('192.168.1.126','admin','','monkey1'); $result=$mysql_conn->query("SELECT * from demo"); echo "<table>"; echo "<th>Test Processor</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['name']; echo "</td></tr>"; } echo "</table>"; $mysql_conn=new mysqli('192.168.1.127','admin','','monkey2'); $result=$mysql_conn->query("SELECT * from demo"); echo "<table>"; echo "<th>Test Processor</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['processor']; echo "</td></tr>"; } echo "</table>"; ?> </body> </html> If 192.168.1.126 is offline, the webpage doesn't go any further and display 192.168.1.127's info...Appreciate any insight... ignore Having a problem with that "insert ignore into". If it is a new record, it works, when it is a excisting record that needs to be updated, it is giving me this error: Cannot execute query: INSERT IGNORE INTO (gedcom,kennel) VALUES ("World","Avongara") What or where is it going wrong? This message is for me not enough to find the problem. $kennels = array(); if( !in_array( $kennel, $kennels ) ) array_push( $kennels, $kennel ); foreach( $kennels as $kennel ) { $query = "INSERT IGNORE INTO $kennels_table (gedcom,kennel) VALUES (\"$tree\",\"$kennel\")"; $result = @mysql_query( $query ) or die ("$admtext[cannotexecutequery]: $query"); } Thanks for helping I want half of the results to to show up with a hyperlink (if I've added the link as a field in my CSV file) and half of the results to show up with no hyperlink. The link URL's are located in field 8 of a database : [8] as seen below. Could anyone help me to figure out how to add an "if" statement perhaps? Something like "if 8 true" then display "<a href"? I did not write this php code I am only modifying it. The csv file is very very straightforward, but this PHP is beyond me. Would appreciate the help! <p><a href="<?=htmlspecialchars($r[8])?>"><?=htmlspecialchars($r[1])?></a><br /> <?=htmlspecialchars($r[2])?><br /> <?=htmlspecialchars($r[3])?><br /> <?=htmlspecialchars($r[4])?><br /> <?=htmlspecialchars($r[5])?><br /> <a href="mailto:<?=htmlspecialchars($r[7])?>"><?=htmlspecialchars($r[7])?></a> </p> Hi I'm currently experiencing a problem with my query. I've used the `INSERT IGNORE` option in my query and it works pretty well not to add duplicates, but the problem is that if my unique field match it doesn't update any other info in the row, is there maybe another option to update a row if an existing field exists but insert new row if it doesn't exists?
my current query is as follow
$query = mysqli_query($con,"INSERT IGNORE INTO mxit (ip,time,user_agent,contact,userid,id,login,nick,location,profile) VALUES ('$ip','$post_time','$mxitua','$mxitcont','$mxituid','$mxitid','$mxitlogin','$mxitnick','$mxitloc','$mxitprof')") or die(mysqli_error($con)); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309981.0 I am working on a little project for my site and I am trying to get this script to ignore the index.html file and the .htaccess file in there. I just want it to display all files like .zip, .rar, .tar, .gz, .gtar, .ace, ect... echo " <td width='70%'><select id='download'>"; echo " <option value=''>None</option>"; if ($handle = opendir("./modules/Downloads/files")) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo " <option value='".$file."'>".$file."</option>"; } } closedir($handle); } echo " </td>\n"; Hello there, I am working on a script that will take a user submitted text and display the text in rainbow. I found a very nice function on the Internet and used it as my base. Here is an example of the code. Code: [Select] function rainbow($text) { /*** initialize the return string ***/ $ret = ''; /*** an array of colors ***/ $colors = array( 'ff00ff', 'ff00cc', 'ff0099', 'ff0066', 'ff0033', 'ff0000', 'ff3300', 'ff6600', 'ff9900', 'ffcc00', 'ffff00', 'ccff00', '99ff00', '66ff00', '33ff00', '00ff00', '00ff33', '00ff66', '00ff99', '00ffcc', '00ffff', '00ccff', '0099ff', '0066ff', '0033ff', '0000ff', '3300ff', '6600ff', '9900ff', 'cc00ff'); /*** a counter ***/ $i = 0; /*** get the length of the text ***/ $textlength = strlen($text); /*** loop over the text ***/ while($i<=$textlength) { /*** loop through the colors ***/ foreach($colors as $value) { if ($text[$i] != "") { $ret .= '<span style="color:#'.$value.';">'.$text[$i]."</span>"; } $i++; } } /*** return the highlighted string ***/ return $ret; } $post[message] = rainbow($post[message]); And it works very well Here is my problem. At times $post[message] will contain some basic html such as a bold tag, user smiley (img tag), a link tag, and so forth. How can I take my function above so that it doesn't edit and add the html font color coding for anything inside html tags where it just skips over them and leaves that part alone? I need this otherwise it will breakup every html tag I might have inside $post[message] and add a font color html tag to it, thus voiding all other html in it. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=345658.0 |