PHP - Search Age Range Based On Birthdate
I have an advanced search from that has 20 fields and it works great however I'm having a problem with customising the age range search based on the $birthdate field (YYYY/MM/DD). The user inputs $agefrom and $ageto and then I don't know how to convert the birthdate field to an age to be able to echo only the users in that age range...
<?php $cQuery = 'true and '; $aSearchcriteria = array(); //more code here...(other search input that works) if(isset($_POST['agefrom']) and trim($_POST['agefrom']) and strip_tags ($_POST['agefrom']) and mysql_real_escape_string ($_POST['agefrom'] )) if(isset($_POST['ageto']) and trim($_POST['ageto']) and strip_tags ($_POST['ageto']) and mysql_real_escape_string ($_POST['ageto'] )) { $cQuery .= "$birthdate BETWEEN '$agefrom' AND '$agefrom' and "; $aSearchcriteria[] = $agefrom; $aSearchcriteria[] = $ageto; } //more code here...(other search input that works) $data = mysql_query("SELECT * FROM table WHERE $cQuery order by name, surname") or die("SELECT Error: ".mysql_error()); // more code here // table echo here... ?> Similar TutorialsHi. Im searching for a way to enter multiple records at once to mysql databased on a date range. Lets say i want to insert from date 2010-11-23 to date 2010-11-25 a textbox with some info and the outcome could look in database like below. ---------------------------------------------------------- | ID | date | name | amount | ----------------------------------------------------------- | 1 | 2010-11-23 | Jhon | 1 | | 2 | 2010-11-24 | Jhon | 1 | | 2 | 2010-11-25 | Jhon | 1 | ----------------------------------------------------------- The reason i need the insertion to be like this is because if quering by month and by user to see vacation days then vacations that start in one month and end in another month can be summed by one month. If its in one record then it will pop up in both months. Help is really welcome. I wish to return the object in an array with the highest index where its index falls between between integers, and return null should one not exist. For instance, with the following and a min and max of 10,000 and 15,000, it should return OBJ4, and with a min and max of 15,000 and 20,000 it should return NULL. Any thoughts? Thanks function getObj(int $min, int $max):?OBJ { $list=[ 12314=>'OBJ1', 321=>'OBJ2', 42142=>'OBJ3', 14314=>'OBJ4', 123=>'OBJ5', 13314=>'OBJ6' ]; return getIt($list, $min, $max); }
Hi Folks, I'm creating an equipment reservation system for a client. Every reservation has an equipmentID, ReservationDate, StartTime, EndTime. So, basically my script searches existing records for a given date and EquipmentID. I'm having trouble with how best to approach validation on new reservations to ensure there are no conflicts. Lets say two existing reservations for a given date/equipment are found. One reservation has a startTime of 8AM and endTime of 9AM. The second has a startTime of 12PM and endTime of 3PM. Is there a simple way to check if the user's submitted values for StartTime and EndTime conflict with existing reservations? Any input would be greatly appreciated! Thanks! -John I thought I'd never have to ask another date related question after the help I got from Pikachu earlier this month but I can't get this simple thing to work. I have a table post for Date of Birth (Format YYYY-MM-DD) and a search form where you select From and To Numbers to find users between these ages. I have tried a few different things - this one works best, if I choose from any number and up til current time I get results but as soon as I set the script to use the selected variable I bomb. Also, somehow I got the script to only return the users with a DOB of 0000-00-00. Here is the current version (shortened to show the relevant parts): Code: [Select] $now = time(); //current timestamp $now=(date("Y-m-d")); if (isset($_POST['ageFr'])) //sets the stopdate for the search $ageFr = sanitizeString($_POST['ageFr']); $yearStop="date_sub($now, INTERVAL $ageFr YEAR)"; if (isset($_POST['ageTo'])) //sets startdate for the same search $ageTo = sanitizeString($_POST['ageTo']); $yearStart="date_sub($now, INTERVAL $ageTo YEAR)"; $query = "SELECT * FROM user_criteria WHERE sex='$sex' AND (age BETWEEN ($yearStart) AND ($yearStop))"; //The query When I echo like this: echo "$ageFr to $ageTo <br />"; echo "$yearStart - $yearStop"; echo "<br /> $query"; I get this: 18 to 101 date_sub(2012-01-24, INTERVAL 101 YEAR) - date_sub(2012-01-24, INTERVAL 18 YEAR) SELECT * FROM user_criteria WHERE sex='Female' AND (age BETWEEN (date_sub(2012-01-24, INTERVAL 101 YEAR)) AND (date_sub(2012-01-24, INTERVAL 18 YEAR))) Shouldn't that work? Am I making a big or a small mistake here? Pikachu? //calculate age $birthdate = "1978-04-26"; //birth date... actually being obtained from a database $today = date("Y-m-d H:i:s"); // The exact date $age = date_diff($str_birthday, $today); echo $age; I'd like a simple code to echo the age of someone with the mysql database information that's in their record. This doesn't work. I have no idea why. Nothing seems to work that I've found on the net. Please help. Thanks. hey guys need some ideas here.. currently i have implemented google maps for multiple search results now i wanted to do the following search based on zip codes and also show the adjacent cities/business based on the searched zip code. in the search result as well as map thanks Is there such thing? I designed a while back a rudimentary form based app for my users. We receive from our suppliers hardware manufacturing data in XML files: file name is made of eleven fields separated by tildes, with each field having its own meaning. R&D guys wanted to be able to search each field of the file names so I used regex() with decent results. Problem is that we have now in the upwards of 2.5 million files. And my app can't hack it anymore. I looked at Apache Lucene & Solr. Though it seemed like the best solution to my problem, the fields in the filenames are not peers to the file content. Big no-no with Solr. What is the best way to implement a PHP app with indexing and search capability with such large number of files? Do I have to buy Zend and use Zend_Search? Is it the only way? Thanks for your input. How can I build a form with a drop down menu with the year, day, month? And then send that information to a database. If there is another/better option besides a drop down menu? If so, please tell me. The rest of the form is working fine, and all the inforamtion is going to the database - last name, first name, address, phone number, zip code, race,,,,,,,,,. I work for a not-for-profit medical office - we provide medical services to the local people who can not afford to go to a regular doctor. We need a simple way to keep track of patient information. One of the things we need to enter is the birthdate. Searching the forums provided a lot of results, but the words date and form are used so much, I can not find anything that helped me. I also looked through php.net, but can not find anything there. Hello, I had 8 select boxes(dropdowns) in a form. Its like a search kind of implementation in the website. I don't know what the user selects, he may choose different select boxes, any number of select boxes. So, based upon the user selection, I need to generate the data. The data fields to be generated would be almost same. So, How would I know what the user selection is and how many select boxes has been selected and how could I generate different data based upon selected boxes. I had to make a small note abt this, that the data generation fields may change for some of the user select combinations, but most of the result fields would be same. so, can you please help me out, how to do, how to make different combination data generations, because, i had 8 fields, i had to make 8! combinations, that would result in a big code. Why is this not working? Code: [Select] $result = mysql_query("SELECT * FROM contacts WHERE type = 'consumer' AND sent BETWEEN '".date("Y-m-d")."' AND '".date("Y-m-d", strtotime("-7 days"))."'") or die(mysql_error()); $numrows = mysql_num_rows($result); if($numrows < 0 ){ echo "No records found"; } The record that is stored in the sent column is like this "2011-11-03 14:42:12", so there is a record in there, but nothing is showing up. Can anyone see why? thanks in advance I am currently working on a date range script and wondering if anybody think of an easier way to do this, doing up to next 8 weeks? This one starts on a Sunday. I also need to do one starting on a Monday (will figure that one later) $thisweek = date("Y-m-d"); $week = date('w', strtotime($thisweek)); $date = new DateTime($thisweek); $firstWeek = $date->modify("-".$week." day")->format("M d"); $endWeek = $date->modify("+6 day")->format("M d"); echo $firstWeek." - "; echo $endWeek; $nextweek = date(("Y-m-d"), strtotime("+7 Days")); $week1 = date('w', strtotime($nextweek)); $date1 = new DateTime($nextweek); $firstWeek1 = $date1->modify("-".$week1." day")->format("M d"); $endWeek1 = $date1->modify("+6 day")->format("M d"); echo $firstWeek1." - "; echo $endWeek1;
This works if say I do 192.168.0.1 - 192.168.1.254 it will work. However doing 192.168.0.1 - 192.168.1.10 will only generate up to .10 on both IP schemes. I see why, but I cannot figure out a way around this... Thanks! $start = explode('.', '192.168.10.1'); $end = explode('.', '192.168.11.10'); /** * Final output... */ $a = 0; $b = 0; $c = 0; $d = 0; // First segment for ($a = $start[0]; $a < 1 + $end[0]; $a++) { // Second segment for ($b = $start[1]; $b < 1 + $end[1]; $b++) { // Third segment for ($c = $start[2]; $c < 1 + $end[2]; $c++) { // Fourth segment for ($d = $start[3]; $d < 1 + $end[3]; $d++) { echo "{$a}.{$b}.{$c}.{$d}<br />"; } } } } I have range of categories from 1 to 999 With this is piece of code: foreach (range(96,204) as $number) if (Tools::getValue('id_category') == $number) return; $this->filterResults(); return $this->display( __FILE__, 'block-center-filter.tpl'); iw managed to avoid display of 'block-center-filter.tpl' in that range but it shows in every other categories. What i need is opposite... i would like to dont show except in that range... how to do that? The result pages is supposed to have pagination like google help me please
I have a simple script that converts an ip range to a readable ip address, e.g 2147483647 = 127.255.255.255 and it works fine up to this range, anything after this causes an incorrect ip address. e.g 2147483648 should be 128.0.0.0 but it outputs 128.0.0.255 and so all ip address after this are incorrect! code I am using is below; $rawip_from = '2147483648'; // raw to readable ip $w1 = (int)($rawip_from / 16777216) % 256; $x1 = (int)($rawip_from / 65536 ) % 256; $y1 = (int)($rawip_from / 256 ) % 256; $z1 = (int)($rawip_from ) % 256; $rawip_to = '2147549184'; // raw to readable ip $w2 = (int)($rawip_to / 16777216) % 256; $x2 = (int)($rawip_to / 65536 ) % 256; $y2 = (int)($rawip_to / 256 ) % 256; $z2 = (int)($rawip_to ) % 256; $ip_from = ($w1.'.'.$x1.'.'.$y1.'.'.$z1); $ip_to = ($w2.'.'.$x2.'.'.$y2.'.'.$z2); echo "Ip raw range: $rawip_from - $rawip_to<p>Ip range: $ip_from - $ip_to"; /* should output Ip raw range: 2147483648 - 2164260863 Ip range: 128.0.0.0 - 128.1.0.0 but it outputs 128.0.0.255 - 128.1.0.255 */ It always seems to add 255 to the last range instead of the correct value????? I heard there is a bug in php with integers > 2147483647 if anyone knows of a fix it would be great!! Thanks... Hi i have the following code Quote
$sql= "SELECT * FROM income WHERE month(date) between '04' and '12' and year(date) between 2020 and 2020"; This obviously selects all the information from April 2020 to December 2020
How do i change this to add a date as well for example if i wanted to display all the information from April 6th 2020 to December 5th 2020 ?
Good Evening, I've created a function to get the Range of an array (Highest Value - Lowest Value). Now I'm trying to use this to find the Range of the Upper Quartile(Q3) and the Lower Quartile(Q1) but am not sure as to what is the best/most efficient way of doing this? Should I find the middle value of the array, and then create 2 new arrays, the top half and bottom half, then use the Range function on each of them to get Q3 and Q1 or is there a better way to go about doing this? $x = array(); sort($x); // calculate median (middle number/value) $count = count($x); $middleval = floor(($count-1)/2); if($count % 2) { $median = $x[$middleval]; } else { $low = $x[$middleval]; $high = $x[$middleval+1]; $median = (($low+$high)/2); } // calculate range $min = min($x); $max = max($x); return $range = $max - $min; any help/suggestions are appreciated! Thank you. Kind Regards, Ace if i want find included a word in the a range how can i do it? example : Quote array("problem is an obstacle, impediment, difficulty or challenge, or any situation that invites resolution; the resolution of which is recognized as a solutionquestion raised for inquiry, consideration, or solution proposition in mathematics or physics stating something to be done"); how can i find only start 20 charecter and my found word after 20 character by end example :if my word be inquiry i want find :...soluti Quote onquestion raised for inquiryconsideration, or solution proposition... [/size] i have the below code which i wrote this monring, for some reason when i assign $date to fetch data from my database i just get the echo of "You had an Error" yet if i manually assign $date as the following it works: Code: [Select] $date = strtotime("2011-09-20"); i have it set exactly the same in the database cus if i echo $date i get: Code: [Select] 2011-09-20 whats going on? date in php is a cruel function to play around with.. here is my code: Code: [Select] <?php // Query the DB to fetch all data where member_id matches that set in session $reminder = mysql_query("SELECT * FROM `reminders` WHERE member_id=$_SESSION[SESS_MEMBER_ID]") or die(mysql_error()); //While Loop the results while($fetch = mysql_fetch_array( $reminder )) { // Start date (TODAY!) $s_date = strtotime("now"); // End Date (+7 days from today) $e_date = strtotime("+1 week"); // Fetches Date stamp from "reminderDate" row in DB $date = $fetch['reminderDate']; // Checks if the date is between 2 ranges set above if($date > $s_date && $date < $e_date) //Echo The Results { echo "<div class='notification error png_bg'><a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a><div>Custom Error Notification BOX!</div></div>"; } else { echo "You had an Error"; //echo $date; // TEST that date outputs datestamp "2011-09-02" } //END LOOP } ?> Hello, I'm very disapointed because I don't know how do it this. I'm explain. I have a database with one input date_arrival and second date_departure. Two dates are saved in SQL format : 2014-03-02. After my SQL request to select all dates in database I'd like to add dates between date_arrival and date_departure and for each line. For example I have date_arrival date_departure line 1 : 2014-02-01 2014-02-05 line 2 : 2014-02-10 2014-02-15 In fact at the end, I have to send the result like this (with JSON) : ["2014-02-01","2014-02-02","2014-02-03","2014-02-04","2014-02-05","2014-02-10","2014-02-11","2014-02-12","2014-02-13","2014-02-14","2014-02-15"] Can you give me some help to add intermediates values in an array ? Thx |