-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
You could replace $number = pow($currentNumber, 2); with $number = $currentNumber * $currentNumber;
-
You could try this method $perth = new DateTimeZone('australia/perth'); $darwin = new DateTimeZone('australia/darwin'); $sydney = new DateTimeZone('australia/sydney'); $time = DateTime::createFromFormat('G:ia', '10:00am', $perth); echo $time->format('G:ia') . " Perth<br>"; $time->setTimezone($darwin); echo $time->format('G:ia') . " Darwin<br>"; $time->setTimezone($sydney); echo $time->format('G:ia') . " Sydney<br>"; /*** RESULTS ********** 10:00am Perth 11:30am Darwin 12:00pm Sydney ***********************/
-
radio button choice needs to control dropdown menu content
Barand replied to edfou's topic in PHP Coding Help
version 2 - sticky buttons <?php if (isset($_GET['gender'])) { $currentGender = $_GET['gender']; } else $currentGender = ''; $genders = array( 'm' => 'Male', 'f' => 'Female' ); $genderTxt = ''; /****************** * sticky buttons *******************/ foreach ($genders as $k=>$v) { $chk = $k==$currentGender ? "checked='checked'" : ''; $genderTxt .= "<input type='radio' name='gender' value='$k' $chk/> $v<br>\n"; } ?> <html> <head> <script type="text/javascript"> // male option values and texts var mvals = Array('m1','m2','m3'); var mtxts = Array('aaa','bbb','ccc'); // female option values and texts var fvals = Array('f1','f2','f3'); var ftxts = Array('xxx','yyy','zzz'); function buildOptions() { var genderval=""; // find current gender value for (var i=0; i<2; i++) { if (document.form1.gender[i].checked) { genderval = document.form1.gender[i].value; } } var selobj = document.getElementById("option"); // clear existing options while (selobj.options.length) { selobj.options[0]=null; } // add gender-dependent options if (genderval=="m") { for (var j=0; j<mvals.length; j++) { selobj.options[j] = new Option(mtxts[j], mvals[j]); } } else if (genderval=="f") { for (var j=0; j<fvals.length; j++) { selobj.options[j] = new Option(ftxts[j], fvals[j]); } } } </script> </head> <body> <form action="" name="form1"> <h3>Gender</h3> <?php echo $genderTxt?> <br> <select name="option" id="option"> <option value="">- Gender options -</option> </select> <br><br> <input type="submit" name="btnsubmit" value="Submit"> </form> <script type="text/javascript"> var i; for (i=0; i<document.form1.gender.length; i++) { document.form1.gender[i].onclick = function(){buildOptions();}; } onload = function(){buildOptions();}; </script> </body> </html> -
Date elements need to be in yyyy-mm-dd sequence to do comparisons. I have already shown you how to do time comparison in http://forums.phpfreaks.com/topic/282512-finding-time-range-between-two-given-times-in-php/?do=findComment&comment=1451618
-
Need a little help with a couple of PhP issues
Barand replied to grungeandgaze's topic in PHP Coding Help
Too many 1's (hr, min, sec, month, day, year) -
Need a little help with a couple of PhP issues
Barand replied to grungeandgaze's topic in PHP Coding Help
$unixTime = mktime(1, 1, 1, 1, $_POST['month'], $_POST['year']); The order of the parameters is wrong in that statement. The final 3 should be month, day, year -
Need a little help with a couple of PhP issues
Barand replied to grungeandgaze's topic in PHP Coding Help
$albumdate = '2012-01-31'; $albummonth = date('F Y', strtotime($albumdate)); //--> January 2012 -
radio button choice needs to control dropdown menu content
Barand replied to edfou's topic in PHP Coding Help
If you want to do it purely with javascript <html> <head> <script type="text/javascript"> // male option values and texts var mvals = Array('m1','m2','m3'); var mtxts = Array('aaa','bbb','ccc'); // female option values and texts var fvals = Array('f1','f2','f3'); var ftxts = Array('xxx','yyy','zzz'); function buildOptions() { var genderval=""; // find current gender value for (var i=0; i<2; i++) { if (document.form1.gender[i].checked) { genderval = document.form1.gender[i].value; } } var selobj = document.getElementById("option"); // clear existing options while (selobj.options.length) { selobj.options[0]=null; } // add gender-dependent options if (genderval=="m") { for (var j=0; j<mvals.length; j++) { selobj.options[j] = new Option(mtxts[j], mvals[j]); } } else if (genderval=="f") { for (var j=0; j<fvals.length; j++) { selobj.options[j] = new Option(ftxts[j], fvals[j]); } } } </script> </head> <body> <form action="" name="form1"> <input type="radio" name="gender" value="m" /> Male<br> <input type="radio" name="gender" value="f" /> Female<br> <br> <select name="option" id="option"> <option value="">- Gender options -</option> </select> <br><br> <input type="submit" name="btnsubmit" value="Submit"> </form> <script type="text/javascript"> var i; for (i=0; i<document.form1.gender.length; i++) { document.form1.gender[i].onclick = function(){buildOptions();}; } </script> </body> </html> -
The date() function returns a formatted date string from a unix timestamp. mktime() requires six integers in the order (hr, min, sec, month, day, year) if $ptime is a unix timestamp, the next day can be found with $next = strtotime('+1 days', $ptime);
-
Finding Time range between two given times in Php
Barand replied to mflevie44's topic in PHP Coding Help
7:15 would also be a correct entry with that logic $t1 = '7:30'; $t2 = '20:30'; $dt1 = DateTime::createFromFormat('G:i', $t1); $dt2 = DateTime::createFromFormat('G:i', $t2); $test = array ('7:15', '7:30', '12:00', '20:00', '20:30', '20:45'); foreach ($test as $t) { $dt = DateTime::createFromFormat('G:i', $t); $res = $dt1 <= $dt && $dt <= $dt2 ? 'OK' : 'Error'; echo "$t $res<br>"; } /* results **** 7:15 Error 7:30 OK 12:00 OK 20:00 OK 20:30 OK 20:45 Error ***************/- 2 replies
-
- php
- unixtimestam
-
(and 2 more)
Tagged with:
-
MYSQL / PHP Distance results... Lat & Long.. help
Barand replied to JordanSmith1111's topic in PHP Coding Help
After 20 seconds Googling http://stackoverflow.com/questions/6264571/calculate-distance-in-km-and-miles If you spend a little more time you might come up with something better -
take a look at the DateTime class, particularly http://www.php.net/manual/en/datetime.createfromformat.php and http://www.php.net/manual/en/datetime.gettimestamp.php and http://www.php.net/manual/en/datetime.diff.php TIP: if you are going to post two different questions don't give the same title - one could get removed as a duplicate post
- 2 replies
-
- unixtimestam
- php
-
(and 1 more)
Tagged with:
-
And although I love having to scroll through 20 pages of code to get to the next reply, would you use the forum's code tags when posting code.
-
Using floating divs is the easiest way. Here's a simple example $a = range(1,90); // array of your data $i = 0; foreach ($a as $data) { echo "<div style='height:80px; width: 100px; font-size: 40pt; text-align: center; float: left; border: 1px solid black;'> $data </div>"; if ($i%6 == 5) { echo "<div style='clear:left'></div>"; } ++$i; }
-
how to step up and down through the result of an sql query
Barand replied to ajoo's topic in MySQL Help
or store the rows in an array -
I had something like this in mind $db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); $fullSectionsArray = array(1,2,3,4,5,6,7,8,9,10); $parentId = 144; $descendants = array(); findDescendants($parentId, $descendants, $db); $descendedFrom144 = array_intersect($descendants, $fullSectionsArray); $notDescended = array_diff($fullSectionsArray, $descendants); function findDescendants($parentId, &$descendants, $db) { $res = $db->query("SELECT category_id FROM category WHERE parent = $parentId"); while ($row = $res->fetch_assoc()) { $descendants[] = $row['category_id']; findDescendants($row['category_id'], $descendants, $db); } }
-
The point is you then only need do a single recursive search and not one for each section_id in the array.
-
Rather than do a recursive search up the hierarchy for every item in the array I would do a single recursive search for all descendants of item 144 and store them in an array. All you need to do then is traverse your original array and check if they are in the array of descendants.
-
try in ($search_string) without the single quotes ($searchstring already has quotes)
-
Have you considered array_intersect()? $itemsToSearch=array("item1","item2","item3"); $ArrayToSearchIn=array("item1","item5","item2","item3","item5","item6"); $res = array_intersect($ArrayToSearchIn, $itemsToSearch); echo '<pre>',print_r($res, true),'</pre>'; /**************************** OUTPUT Array ( [0] => item1 [2] => item2 [3] => item3 ) *******************************/
-
What code have you got so far?
-
Are you trying to create a single SQL query linking the tables or do you want two linked selection dropdowns.? We need more info on what you are trying to do