PHP - Searching On Age Range When Dob Is Stored As Timestamp
i'm stuck with searching on age query
i let users register their date of birth (they give in DAY, MONTH, YEAR) --> column 3 Name CalcAge Timestamp Timestamp calculated for query Person 1 21 659948401 642754801 Person 2 39 91954801 83746801 Person 3 15 849337201 848991601 Person 4 33 281257201 281170801 Person 5 23 596876401 600850801 Person 6 87 -1422809999 -1422723599 I came up with the following query to search between a minimum and maximum age (using AJAX): Code: [Select] //user enters a minimum and/ or max age - getting the querystring from URL (ajax) $minAge = $_GET['minAge']; $maxAge = $_GET['maxAge']; //age to unix timestamp function agetostamp($age){ $gebjaar = date(Y) - $age; $timestamp = mktime (0,0,1,0,0,$gebjaar); return $timestamp; } //making getvariables timestamp in order to compare with database if (isset ($minAge)){ $minAge = agetostamp($minAge); } if (isset ($maxAge)){ $maxAge = agetostamp($maxAge); } //building query query = "SELECT * FROM respondenten WHERE geslacht = '$sex'"; if(is_numeric($minAge) && $minAge > 0) $query .= " AND geboortedatum <= '$minAge'"; else if (is_numeric($minAge)) $query .= " AND geboortedatum >= '$minAge'"; if(is_numeric($maxAge) && $maxAge > 0) $query .= " AND geboortedatum <= '$maxAge'"; else if (is_numeric($minAge)) $query .= " AND geboortedatum >= '$maxAge'"; I encouter a lot of troubles working like this: 1) if i leave out the part of maxAge (so i only allow to set a minimum age in the search box) it works except for the fact that if i set the minimum age to 23, person 5 will not be included since 596876401 < 600850801 even though she is 23 and should be included. 2) if i add the part of also searching on a max age, i don't get any results I know that remark 1 probably has to do with the fact that im using date(Y) - $age and that people that are already born this year will have a timestamp higher than the one calculated in the query and visa versa. conclusion: i don't think i'm going to get out of this so i'm hoping sombody can help me, telling me how to build a query for selecting on age range Similar TutorialsI have read that i can search for a number within a mysql database using BETWEEN i.e: SELECT * FROM `table_name` WHERE `field_name` BETWEEN 99 AND 200 How would i do this with the code below? <?php $salary = explode(":", $_GET['salary_to']); } $types[] = (isset($_GET['salary_to']) && strlen(trim($_GET['salary_to'])) > 0) ? "`salary_from` LIKE '%". mysql_real_escape_string(trim($salary[0])) ."%' AND `salary_to` LIKE '%". mysql_real_escape_string(trim($salary[1])) ."%'" : ''; ?> Thanks for any help I think I've coded myself into a corner. I have numerous items entered with measurement extremes - highest and lowest. Now I want somebody to be able to search for an item that could match a specific length. So I could have several items that are entered into a database like this: Code: [Select] item_id | length | high_low_param -----------+-----------+---------------------- 1234 | 12 cm | high -----------+-----------+--------------------- 1234 | 6 cm | low If somebody searches for an item that is 8 cm long, I want the results to be item 1234 and any other items that span that range. I'm not sure how to do this? array_fill ? I don't know. I don't want to slow down the database too much, and I don't want to have to put an entry for every single length each item could be. Any suggestions? wrote a stored procedure this morning and i don’t know how to get the values out of it through a class function in php or phpmyadmin. here is what i wrote : public function totalProcedures($friend_name,$session_id) { /* *query to fetch stored procedure */ try { //executing the stored procedure $sql_sp="CALL timeline (:friend, :session,@updates, @group_posts)"; $stmt_sp= $this->_db->prepare($sql_sp); $stmt_sp->bindValue(":friend",$friend_name); $stmt_sp->bindValue(":session",$session_id); $stmt_sp->execute(); $rows=$stmt_sp->fetch(PDO::FETCH_ASSOC); $stmt_sp->closeCursor(); // closing the stored procedure //trying to get values from OUT parameters. $stmt_sp_2=$this->_db->prepare("select @updates,@group_posts"); $stmt_sp_2->execute(); return $stmt_sp_2->fetch(PDO::FETCH_ASSOC); } catch (PDOException $ei) { echo $ei->getMessage(); } } can someone helpme how to get results. here is the storedprocedu DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeline`(IN `friend` VARCHAR(255), IN `session_id` VARCHAR(255), OUT `updates` VARCHAR(62555), OUT `group_posts` VARCHAR(62555)) BEGIN select * FROM updates where author in (friend,session_id) order by time desc limit 5; select * FROM group_posts where author_gp in (friend,session_id) order by pdate desc limit 5; END$$ DELIMITER ; i get the result in php myadmin as follows:
how do i do this inside a php class function. CALL timeline('shan2batman','aboutthecreator', @updates, @group_posts);
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;
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? 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 />"; } } } } Hi Everyone, I have this php page that runs couple of MS SQL stored procedures to fetch me values from SQL Server, however I have run into a problem where not more then 2 stored procedures are executed at same time. For instance below mentioned code only fetches me values for 1st and 2nd SP's. If I need values from the 3rd stored procedure then I would have to comment either one of the first two stored procedure. Can someone please tell me what is that I am doing wrong. I am relatively new to PHP, so please be gentle. Any help would be highly appreciated. Thanks. <?php if($conn = mssql_connect('host', 'user', 'pass')) echo 'Connected to SQLEXPRESS<BR>'; if(mssql_select_db("database",$conn)) echo 'Selected DB: SomeDatabase<BR>'; $variable1=something; $sql_statement = mssql_init("stored_procedure1 '$variable1'", $conn); $result=mssql_execute($sql_statement); $x=0; while ($row = mssql_fetch_assoc($result)) { $column2[$x]= $row['column2']; $column1= $row['column1']; $x++; } echo "Value 1: $column1 </br>"; echo "Value 2: $column2[0] </br>"; echo "Value 3: $column2[1] </br>"; echo "Value 4: $column2[2] </br>"; echo "Value 5: $column2[3] </br>"; echo "Value 6: $column2[4] </br>"; echo "Value 7: $column2[5] </br>"; mssql_free_statement($sql_statement); $sql_statement = mssql_init("stored_procedure2 '$variable1'", $conn); $result=mssql_execute($sql_statement); $x=0; while ($row = mssql_fetch_assoc($result)) { $someval1[$x]= $row['somecolumn1']; $someval2[$x]= $row['somecolumn2']; $someval3= $row['somecolumn3']; $someval4= $row['somecolumn4']; $someval5= $row['somecolumn5']; $someval6= $row['somecolumn6']; $x++; } echo "Something1: $someval1[0]</br>"; echo "Something2: $someval3 </br>"; echo "Something3: $someval2[0] </br>"; echo "Something4: $someval4 </br>"; echo "Something5: $someval6 </br>"; echo "Something6: $someval5 </br>"; mssql_free_statement($sql_statement); $sql_statement = mssql_init("stored_procedure3 '$variable1'", $conn); $result=mssql_execute($sql_statement); $x=0; while ($row = mssql_fetch_assoc($result)) { $somevaluecheck= $row['somecolumncheck']; $x++; } echo "SomethingCheck: $somevaluecheck </br>"; mssql_free_statement($sql_statement); ?> The path to a image is stored in a variable and I need to display this image in the email. Can someone help me. This is my current attempt and nothing is happening. But the variable passes the URL correctly. Code: [Select] <TABLE BORDER='0'> <TR> <TD align='left' width='370'><img src='".$dis_logoimg."' width='370' height='86' /></TD> </TR> </TABLE> I'm working on a project and cannot figure out why one piece of code works in one project but not in this one. Code: [Select] $username = "voltageme5"; $result = $mysqli->query("call usernameCheck($username)"); returns string(43) "Unknown column 'voltageme5' in 'field list'" Here is the stored routine: Code: [Select] CREATE PROCEDURE `database`.`table` (IN memUsername varchar(45)) BEGIN select count(*) as total from members where username = memUsername; END Whats weird is that in the PHP code if i replace the variable with a string, it works. It's only with the variable in the call that it errors out like that. I'm new to this stored procedure thing so I'm sure I'm missing something stupid. Often times I need to convert between PHP Arrays, MySQL, XML, JSON sqlite etc. Lately I've been just building PHP arrays with all the data. Its a big hassle though when theres a lot of data. I'm thinking I should have one central location that I store data in, then export to other formats from there, but I dont know what that central location should be. I like MySQL because I'm used to it. Sometimes its not an option though, like if I need to make a really light script, I dont want the hassle of connecting to MySQL. Would XML be the best place to store data, then from the XML file I can convert it to whatever format I want?
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 Hi, I am trying to come up with the best way to create a range voting form. Each candidate will have a "confidence" value associated with the choice.(using a pulldown menu?) So for March Madness it would be: Team ....... Confidence Value..... each team could only be voted to finish the tournament in a particular place, and a value would be associated with that choice. The total choices possible determines the range of confidence value possible. So....if there are 16 teams to vote on....the confidence value would range from 1-16. The voter would assign his highest available value to the team he was most confident in landing in that particular position. Example: 16 teams - 16 conf vals - if certain Duke will end up at #1 - then vote : #1 = Duke, conf val 16 next, if almost as certain that NC will end up last - then vote: #16 = NC, conf val 15 next most certain "", conf val 14 and so on.... the tricky part is making sure that the form code validates each conf val so that it is used, but used on ly once.... ideally the form could return values that could then be imported into excel and comopared. has this been done somewhere? Can you help ? hope so.... thanks!! 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 Ok, my subject line may not be exactly what I am looking for and I am not even sure what the subject should be, so let me explain what I am trying to do. My application is as such that you enter in a zip code and it returns information, however my hard copy has a range of zip codes, in this case, equaling a zone, I.E. 90076-90210 is zone A, now instead of having the following in the database: Code: [Select] ID ZIP ZONE 1 90076 a 2 90077 a 3 90078 a ... ... 134 90210 a Could I make it: Code: [Select] ID SZIP EZIP ZONE 1 90076 90210 a and though my PHP/mySQL callout compare the variable to, and find that is ZIP is between SZIP and EZIP to output a? As there are a couple od thousand zip codes I am trying to minimize my database to be a bit smaller, but am not sure how to code it. Normally I would make the database have all 99000 entries and pull from the database where ZIP = ZIP, but again I am trying to save my self some time... Could I make it somehow that if ZIP <= SZIP and >= EZIP output ZONE? Does this make any sense? My PHP Coding is unfortunately lacking, I have only been programming it heavily for the last 5 months and it has been basic stuff. Any help would be appreciated. Okay we are using a javascript, but the javascript that the site comes from has bans all irans ips... and it loads slow for those people, how would I place a if statement saying dont load this javascript if in Iran, thanks... I know how to do it, but I can't find a real set number, and I would use just 1 ip but the guy has dynamic... thanks ahead of time So I already have this below...
$state = array ( Can those numbers be a range -- 1-16, 17-32, 33-48 and 49-64 -- without just listing them all?
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 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... I can not get the below to work: if(time() < strtotime("11/21/2011 3:30AM EST") && time() > strtotime("11/21/2011 2:30PM EST")) It should be evaluating to true between 3:30 AM and 2:30 PM EST for today. Now that it's past 2:30PM it should be evaluating to false, but it's coming up as true. Edit: Nevermind. Cache/Cookies Issue. |