lovephp Posted June 3, 2015 Share Posted June 3, 2015 im trying to set the $criteria to session but when i print only the $criteria[] = "Employment = '".$employment."'"; and $criteria[] = "YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '".$agefrom."' AND '".$ageto."'"; are getting the values of print_r($criteria); Array ( [0] => Employment = 'Employed' [1] => YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '18' AND '25' ) if(isset($_POST['submit'])){ $employment = mysql_real_escape_string($_POST['employment']); $mstatus = mysql_real_escape_string($_POST['mstatus']); $agefrom = mysql_real_escape_string($_POST['agefrom']); $ageto = mysql_real_escape_string($_POST['ageto']); $criteria = array(); if($employment !='') { $criteria[] = "Employment = '".$employment."'"; } if($mstatus !='') { $criteria[] = "Maritalstatus = '".$mstatus."'"; } if($agefrom !='' && $ageto !='') { $criteria[] = "YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '".$agefrom."' AND '".$ageto."'"; } $_SESSION['criteria'] = $criteria; } print_r($criteria); Quote Link to comment https://forums.phpfreaks.com/topic/296617-session-wont-to-all-variables/ Share on other sites More sharing options...
QuickOldCar Posted June 3, 2015 Share Posted June 3, 2015 (edited) Set them as associative named arrays. //make sure starting session session_start(); if(isset($_POST['submit'])){ //is a database connection started? //trim and consider pdo or mysqli_* functions $employment = mysql_real_escape_string($_POST['employment']); $mstatus = mysql_real_escape_string($_POST['mstatus']); $agefrom = mysql_real_escape_string($_POST['agefrom']); $ageto = mysql_real_escape_string($_POST['ageto']); if(!$_SESSION['criteria']){ $_SESSION['criteria'] = array(); } if($employment !='') { $_SESSION['criteria']['employment'] = $employment; } if($mstatus !='') { $_SESSION['criteria']['status'] = $mstatus; } if($agefrom !='' && $ageto !='') { $_SESSION['criteria']['agefrom'] = $agefrom; $_SESSION['criteria']['ageto'] = $ageto; } if(!empty($_SESSION['criteria'])){ echo "<pre>"; print_r($_SESSION['criteria']); echo "</pre>"; } } Edited June 3, 2015 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/296617-session-wont-to-all-variables/#findComment-1513080 Share on other sites More sharing options...
Solution lovephp Posted June 3, 2015 Author Solution Share Posted June 3, 2015 got it, actually there was issues with the names of fields in search.php but facing another issue if there isnt any search query the sesseion still displays results from more.php thought i added unset($criteria); if(isset($_POST['page'])): $paged=mysql_real_escape_string($_POST['page']); if(isset($_SESSION['criteria']) && !empty($_SESSION['criteria'])) { //assign to local var if available $criteria = $_SESSION['criteria']; $sql="SELECT * FROM profiles WHERE " . implode(' AND ', $criteria)." ORDER BY UserID DESC"; if($paged>0){ $page_limit=$resultsPerPage*($paged-1); $pagination_sql=" LIMIT $page_limit, $resultsPerPage"; } else{ $pagination_sql=" LIMIT 0 , $resultsPerPage"; } $result=mysql_query($sql.$pagination_sql); $num_rows = mysql_num_rows($result); if($num_rows>0){ while($data=mysql_fetch_array($result)){ $fname=$data['dob']; $lname=$data['Lname']; echo "<table border='0'> <tr> <td width='20%'> <img src='uploads/profiles/1432715714.jpg' class='loadimg'> </td> <td width='80%'> <h3>Balaswami Surraminiam</h3> <b>Age:</b> 60 <br/> <b>Caste:</b> $fname <br/> <b>Height:</b> 4' 5'' <br/> <b>Profession:</b> Chartered Accountant <br/> <b>Location:</b> Badarpur Rly Township <br/> <a href='#'>view profile</a> </td> </tr> </table>"; } } if($num_rows == $resultsPerPage){?> <li class="loadbutton"><button class="loadmore" data-page="<?php echo $paged+1 ;?>">More. </button></li> <?php }else{ echo "<li class='loadbutton'><span class='endload'> No more. </span></li>"; unset($criteria); } } endif; ?> Quote Link to comment https://forums.phpfreaks.com/topic/296617-session-wont-to-all-variables/#findComment-1513081 Share on other sites More sharing options...
lovephp Posted June 3, 2015 Author Share Posted June 3, 2015 got it i added unset($_SESSION['criteria']); this works Quote Link to comment https://forums.phpfreaks.com/topic/296617-session-wont-to-all-variables/#findComment-1513082 Share on other sites More sharing options...
QuickOldCar Posted June 3, 2015 Share Posted June 3, 2015 Maybe you want unset($_SESSION['criteria']); Quote Link to comment https://forums.phpfreaks.com/topic/296617-session-wont-to-all-variables/#findComment-1513083 Share on other sites More sharing options...
QuickOldCar Posted June 3, 2015 Share Posted June 3, 2015 Beat me to it. 1 Quote Link to comment https://forums.phpfreaks.com/topic/296617-session-wont-to-all-variables/#findComment-1513084 Share on other sites More sharing options...
lovephp Posted June 3, 2015 Author Share Posted June 3, 2015 thanks alot bro.. Quote Link to comment https://forums.phpfreaks.com/topic/296617-session-wont-to-all-variables/#findComment-1513085 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.