Jump to content

variable value


proctk

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.