PHP / MySQL Select products below a value in the table

0

I need to select products with a value below 300 reais in which the situacao column is equal to 2 :

Example: in the shopping table I have 8 products registered:

1 sapato valor 25 situacao 1    
2 calça valor 50 situacao 2    
3 meia valor 60 situacao 2    
4 sandália valor 70 situacao 1    
5 bicicleta valor 120 situacao 2    
6 pc core 2 duo valor 250 situacao 2    
7 notebook valor 500 situacao 2    
8 ipad 8 gb valor 600 situacao 2

I tried to do this, but it did not work:

$query = mysql_query("SELECT valor, MAX($valor) FROM ofertas WHERE situacao = '2'") or print (mysql_error());
$query = mysql_query("SELECT valor,FROM ofertas WHERE  MAX($valor) AND situacao = '2'") or print (mysql_error());

Being that I need it done in the format above or as simple as possible.

    
asked by anonymous 11.09.2017 / 19:09

2 answers

0

So, to get the values below 300 reais, just do this:

SELECT * FROM tabela WHERE valor < 300 AND outrasCondicoes...;

To get the highest value:

SELECT max(valor) FROM tabela WHERE outrasCondicoes...

To get the highest value, below 300 reais:

SELECT max(valor) FROM tabela WHERE valor < 300 AND outrasCondicoes...

Would that be?

    
11.09.2017 / 19:14
0
  

I need to select products with a value below 300 reais in which   the column situation equals 2:

$query = mysql_query("SELECT * FROM ofertas WHERE situacao LIKE '2' AND valor < 300") or print (mysql_error());

This deducing that your code is correct at this point and the situation is in text format, if not, instead of using LIKE '2' you should only use = 2 , thus:

$query = mysql_query("SELECT * FROM ofertas WHERE situacao = 2 AND valor < 300") or print (mysql_error());

The same goes for 300 , if it is in text format you should use LIKE '300'

    
11.09.2017 / 19:37