-1

When I enter only min value then it consider max as zero and return me null data

$min=$_REQUEST['min'];     
$max=$_REQUEST['max'];     
$q3="select * from product where '$min' < `price` < '$max'";    
$q=mysql_query($q3);
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
MahajanSagar
  • 740
  • 1
  • 6
  • 21
  • what do you mean null data? you haven't even fetched the rows yet. and please stop using `mysql_` functions. use mysqli or PDO instead with prepared statements – Kevin Oct 31 '14 at 08:14
  • `when i enter only min value then it consider max as zero `: So when you dont provide max what should max be? – Hanky Panky Oct 31 '14 at 08:14

2 Answers2

0

If you do not provide value in your request, php will consider it as NULL. You should have to provide value every time or you can do this .

$min=$_REQUEST['min'];

$max=$_REQUEST['max'];

if(!$max){
   $max = 45; // or what ever value you like
}

$q3="select * from product where price > '$min' and price < '$max' ";

$q=mysql_query($q3);
Neeraj Verma
  • 495
  • 4
  • 17
0

Change the query by max value:

$min=$_REQUEST['min'];

$max=$_REQUEST['max'];

if( empty($max) )
   $q3="select * from product where price > '$min'";
else
   $q3="select * from product where price > '$min' and price < '$max' ";


$q=mysql_query($q3);

One more correction you should start using PDO . method your are using is depreciated.

Read This

Community
  • 1
  • 1
CS GO
  • 914
  • 6
  • 20