proctk Posted February 19, 2007 Share Posted February 19, 2007 below is code that works as a search function. It does the trick but when the user executes the $sortBy block of code the search value is lost. how do the variable $search to kepp its value so that it can be used with the sort feature <?php include ("Connections/dblocal.php"); $search = mysql_real_escape_string($_POST['search']); echo $search; $start = 0; if(isset($_GET['start'])) { $start = intval($_GET['start']); } $end = $start + 5; $sortBy = 'ad_date'; if (isset($_POST['sortBy'])) { $sortBy = $_POST['sortBy']; } echo $sortBy; $query_sql_get_ads = ("SELECT * FROM ads WHERE title LIKE '%$search%' OR category LIKE '%$search%' OR sub_category LIKE '%$search%' order by $sortBy desc LIMIT $start, $end"); $sql_get_ads = mysql_query($query_sql_get_ads)or die("SQL Error: $query_sql_get_ads<br>" . mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/39104-variable-value/ Share on other sites More sharing options...
superuser2 Posted February 19, 2007 Share Posted February 19, 2007 I don't get what it is you are trying to do. Could you explain more? Link to comment https://forums.phpfreaks.com/topic/39104-variable-value/#findComment-188322 Share on other sites More sharing options...
superuser2 Posted February 19, 2007 Share Posted February 19, 2007 The $search variable isn't being changed. If you need to make a copy of it so you can change the original: <?php $search = "test"; $searchB = $search; $search = "something differnet"; echo $searchB; //Outputs 'test', just like the original 'search' ?> Link to comment https://forums.phpfreaks.com/topic/39104-variable-value/#findComment-188324 Share on other sites More sharing options...
proctk Posted February 19, 2007 Author Share Posted February 19, 2007 I don't want the value to change. Its not keeping its keeping its value once I select a the Sort by. I confirmed the by echoing the values $search and $SortBy. The first search both values are displayed buy when i select a value from the sort select on the same page the value of $search is lost but the value of $sortBy changes with the selected value hope this helps Link to comment https://forums.phpfreaks.com/topic/39104-variable-value/#findComment-188327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.