Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. You could replace $number = pow($currentNumber, 2); with $number = $currentNumber * $currentNumber;
  2. 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 ***********************/
  3. 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>
  4. 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
  5. Too many 1's (hr, min, sec, month, day, year)
  6. $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
  7. $albumdate = '2012-01-31'; $albummonth = date('F Y', strtotime($albumdate)); //--> January 2012
  8. 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>
  9. 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);
  10. 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 ***************/
  11. 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
  12. 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
  13. 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.
  14. 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; }
  15. or store the rows in an array
  16. 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); } }
  17. The point is you then only need do a single recursive search and not one for each section_id in the array.
  18. 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.
  19. try in ($search_string) without the single quotes ($searchstring already has quotes)
  20. INNER JOIN `adjuster` B ON `A`.`adjuster_id` = `B`.`id` Everything inside backticks is taken to be a single identifier. Just get rid of them, you don't need them.
  21. That is because you are including the table alias inside the backticks with the table name FROM `ee` A not FROM `ee A` You only need backticks if your table name is a reserved word or contains spaces or other special characters
  22. 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 ) *******************************/
  23. What code have you got so far?
  24. 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.