Jump to content

lovephp

Members
  • Posts

    530
  • Joined

  • Last visited

Everything posted by lovephp

  1. ok i need not convert age of users the following query does the work SELECT * FROM profiles WHERE YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN $agefrom AND $ageto need help with the search criteria $conditions = array() if ($gender !='') { $conditions[] = gender is <value> } if ($religion !='') { $conditions[] = religion is <value> } if ($language !='') { $conditions[] = language is <value> } if ($caste !='') { $conditions[] = caste is <value> } if ($state !='') { $conditions[] = state is <value> } if ($employment !='') { $conditions[] = employment is <value> } if ($mstatus !='') { $conditions[] = mstatus is <value> } if ($agefrom !='' && $ageto !='') { $conditions[] = age between agefrom and ageto } query = SELECT ... if $conditions { query .= WHERE implode(AND, $conditions) } how do i acheive to use the criteria with the above code? thanks
  2. i have changed the dob format to 1980-09-16 the following code calculates and outpot age of all users function userAge($userAge){ $age = strtotime($userAge); if($age === false){ return false; } list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age)); $now = strtotime("now"); list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now)); $age = $y2 - $y1; if((int)($m2.$d2) < (int)($m1.$d1)) $age -= 1; return $age; } $result = mysql_query("SELECT * FROM profiles"); while ($row = mysql_fetch_array($result)){ echo $age = userAge($dob= $row["dob"]); }
  3. ok here is my db structure -- -- Table structure for table `profiles` -- CREATE TABLE IF NOT EXISTS `profiles` ( `UserID` int(11) NOT NULL AUTO_INCREMENT, `ProfileBY` varchar(100) NOT NULL, `Fname` varchar(100) NOT NULL, `Lname` varchar(100) NOT NULL, `Gender` varchar(6) NOT NULL, `Religion` varchar(100) NOT NULL, `Language` varchar(100) NOT NULL, `Caste` varchar(100) NOT NULL, `State` varchar(100) NOT NULL, `Employment` varchar(100) NOT NULL, `mstatus` varchar(100) NOT NULL, `dob` varchar(12) NOT NULL, PRIMARY KEY (`UserID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `profiles` -- [code] here is how am trying to get all age from database [php] $result = mysql_query("SELECT * FROM profiles"); while ($row = mysql_fetch_array($result)){ $dob= $row["dob"]; } $birthDate = "".$dob.""; $birthDate = explode("-", $birthDate); $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")- $birthDate[2])-1):(date("Y")-$birthDate[2])); [/php] then here are the complete coding i tried to implant your way to do the search but i don't know what to do next. with the contions and values for query your way. [php] <?php include("manage/connect.php"); if(isset($_POST['submit'])){ $gender = $_POST['gender']; $religion = $_POST['religion']; $caste = $_POST['caste']; $state = $_POST['state']; $employment = $_POST['employment']; $mstatus = $_POST['mstatus']; $agefrom = $_POST['agefrom']; $ageto = $_POST['ageto']; $result = mysql_query("SELECT * FROM profiles"); while ($row = mysql_fetch_array($result)){ $dob= $row["dob"]; } $birthDate = "".$dob.""; $birthDate = explode("-", $birthDate); $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")- $birthDate[2])-1):(date("Y")-$birthDate[2])); $conditions = array() if ($gender !='') { $conditions[] = gender is <value> } if ($religion !='') { $conditions[] = religion is <value> } if ($language !='') { $conditions[] = language is <value> } if ($caste !='') { $conditions[] = caste is <value> } if ($state !='') { $conditions[] = state is <value> } if ($employment !='') { $conditions[] = employment is <value> } if ($mstatus !='') { $conditions[] = mstatus is <value> } if ($agefrom !='' && $ageto !='') { $conditions[] = age between agefrom and ageto } query = SELECT ... if $conditions { query .= WHERE implode(AND, $conditions) } } ?> [/php] how do i do the rest? thanks :-)
  4. appreciate it mate. but its kinda tough for me doing it like you explained i would not be able to. could you help me out complete the code? would really be thanklful :-)
  5. Mates below is the $post details that i give users to search db Array ( [gender] => female [religion] => Christian [language] => English [caste] => Catholic [state] => Florida [employment] => Employed [mstatus] => Never Married [agefrom] => 18 [ageto] => 25 the query i could do something like select * from some_db WHERE gender LIKE %$query% OR religion LIKE %$query% etc etc but when it comes to age if you can see [agefrom] => 18 [ageto] => 25 my issue is in dob field i store date of birth like 12-12-1980 so how on earth i make it happen to calculate age range between 18-25? how do i even convert the date of birth to age and then do the search query? Really appreciate your valuable time and help in advance, Cheers
  6. i got it sorted code works fine issue was my sql query thanks for your time appreciate it
  7. I dunno but do you think it has to be done with a for loop? Been trying for a long time but unable to get the results it would delete only one image
  8. hey all, my code here works alright but just that when it comes to deleting a posts its unable to delete all images off the uploads/images folder, it unlink just one image related to the topic whereas i want all images unlinked when i delete the topic $cid =$_REQUEST['cid']; $tid =$_REQUEST['tid']; if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true) { $sql="SELECT * FROM posts WHERE post_topic ='".$tid."'"; $result = mysql_query($sql); if(!$result){ }else{ while($row = mysql_fetch_array($result)){ if (mysql_num_rows($result)) { if(!unlink($row['post_img'])){ } } // sending query mysql_query("DELETE FROM topics WHERE topic_id = '".$tid."' AND topic_cat = '".$cid."'")or die(mysql_error()); mysql_query("DELETE FROM posts WHERE post_topic = '".$tid."'")or die(mysql_error()); $result= mysql_query($sql); } header("Location: category.php?id=".$cid.""); } }else{ header("Location: category.php?id=".$cid.""); } appreciate you help.
  9. How to acheive it friends? i want my current codes to show results accouding to current month followed by year, the precious month goes to the page two. would really appreciate if someone could help me acheive it $tableName="records"; $targetpage = "sales.php"; $limit = 1000; $cur_month = date("Y-m"); $query = "SELECT COUNT(*) as num FROM $tableName WHERE Customer_Status = 'Sale' AND DATE_FORMAT(Date, '%Y-%m') = '$cur_month' ORDER BY id DESC"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; $stages = 1; $page = mysql_escape_string($_GET['page']); if($page){ $start = ($page - 1) * $limit; }else{ $start = 0; } // Get page data $query1 = "SELECT id, Date, User, Team, Transfer_Number, Agent_Name, Cell_Phone, Customer_Name, Customer_Status FROM $tableName WHERE Customer_Status = 'Sale' AND DATE_FORMAT(Date, '%Y-%m') = '$cur_month' ORDER BY id DESC LIMIT $start, $limit"; $result = mysql_query($query1); // Initial page num setup if ($page == 0){$page = 1;} $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $LastPagem1 = $lastpage - 1; $paginate = ''; if($lastpage > 1) { $paginate .= "<div class='paginate'>"; // Previous if ($page > 1){ $paginate.= "<a href='$targetpage?page=$prev'>previous</a>"; }else{ $paginate.= "<span class='disabled'>previous</span>"; } // Pages if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few? { // Beginning only hide later pages if($page < 1 + ($stages * 2)) { for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // Middle hide some front and some back elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // End only hide early pages else { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } } // Next if ($page < $counter - 1){ $paginate.= "<a href='$targetpage?page=$next'>next</a>"; }else{ $paginate.= "<span class='disabled'>next</span>"; } $paginate.= "</div>"; } echo "Total Records:".$total_pages; echo '<br/><br/>'; // pagination echo $paginate; }
  10. Friends on my few php scripts i used header('Location: somefile.php'); which worked just fine until yesterday the redirects stopped to work, im on a shared web hosting and the hosting people said they made no changes to their server, i tried error reporting but no error shows the pages which should actually do the redirection displays a blank page with no error warnings on it. what could be the issue any idea?
  11. tried it this way too but it lets post submitted just once but even if i change month in db to make it more than 31 days it wont let data get submitted if($homePhone != '') { $qry = "SELECT homePhone, date_time FROM `table` WHERE homePhone LIKE '%".$homePhone."%' AND `date_time` > CURDATE() - INTERVAL 31 DAY"; $result = mysql_query($qry); if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Customer already exist, data was submitted less than 31 days ago, Try next!'; $errflag = true; } }
  12. this below lets number to be entered once but even if i change month in db to make it more than 31 days the data still not getting submitted it throws in the error message if($homePhone != '') { $qry = "SELECT * FROM `table` WHERE `homePhone` = $homePhone AND `date_time` >= NOW() - INTERVAL 31 DAY"; $result = mysql_query($qry); if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Customer already exist, data was submitted by someone less than 31 days ago, Try next!'; $errflag = true; } }
  13. ok see i got this form where user submits survey and i want to make sure that a customer with same phone number does not get submitted into database in less than 31 days. over 31 days of being submitted it should get submitted but not less than 31 days here is the code $errmsg_arr = array(); //Validation error flag $errflag = false; $customerName = mysql_real_escape_string($_POST['customerName']); $customerAddress = mysql_real_escape_string($_POST['customerAddress']); $homePhone = mysql_real_escape_string($_POST['homePhone']); if($homePhone != '') { $time_count = 31*24*60*60; $match_time = time() - $time_count; $qry = "SELECT homePhone, count FROM data WHERE homePhone='$homePhone' AND `count` > '".$match_time."'"; $result = mysql_query($qry); if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Customer already exist, data was submitted less than 31 days ago, Try next!'; $errflag = true; } } //If there are input validations, redirect back to the form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: add-record.php"); exit(); } //Create INSERT query $qry = "INSERT INTO data (customerName, customerAddress, homePhone, count ) VALUES ('$customerName', '$customerAddress', '$homePhone', '".time()."')"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: record-success.php"); exit(); }else { die("Query failed"); }
  14. still no affect data still gets submitted $homePhone = mysql_real_escape_string($_POST['homePhone']); if($homePhone != '') { $qry = "SELECT * FROM table WHERE homePhone='$homePhone' AND date_time > CURDATE() - INTERVAL 31 DAYS"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Data not posted, number was already posted by someone less than 31 days ago'; $errflag = true; } } } my date column is like this `date_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  15. i did this but data still gets posted? $homePhone = mysql_real_escape_string($_POST['homePhone']); if($homePhone != '') { $qry = "SELECT * FROM table WHERE homePhone='$homePhone' AND date_time < DATE_SUB(NOW(), INTERVAL 31 DAYS)"; $result = mysql_query($qry); if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Data not posted, number was already posted by someone less than 31 days ago'; $errflag = true; } }
  16. yes mysql. would appreciate if someone could help me out im not getting idea how to get it done,
  17. hi friends could someone help with this criteria? i want to restrict entry to db if the post value number was entered into db less than 31 days ago? if($homePhone == '') { $qry = "SELECT * FROM table WHERE homePhone='$homePhone '"; $errmsg_arr[] = 'Data not posted, number was posted by someone less than 31 days ago'; $errflag = true; } in db i store time in datetime current timestamp like 2013-07-13 21:19:15 could someone help me out?
  18. friend the code display all the managers name <?php echo '<select name="Manager">'; $query="SELECT * FROM managers"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['manager_name'] . "'>" . $row['manager_name'] . "</option>"; } echo '</select>'; ?> and the variable below displays the result $Manager= $row['Manager'] ; but how do i do it on the above dropdown list the it shows which result is in the $Manager variable?
  19. well session gets cleaned up way before 24mins sometimes even if idle for 3mins, how you show me how exactly i save session to different folder?
  20. thanks ues i definitely should do a little more study for sure
  21. the problem am as of now facing is within few mins of login the script automatically logs out if no activity. yes i got is solved it by session.gc_maxlifetime = 21600 by default it is 1440 but this is a headache can i not do something with the above code to make session last for longer?
  22. thats with class i do not understand much.
×
×
  • 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.