Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm trying to print the apartments that are below the price I set, but it displays the contents of the entire table.

Entering the price is done from here: http://localhost/yourName/users/57,000

the code for controller :

public function actionView($params){
		if(is_numeric($params[0])){
				$id=$params[0];
		}
		else {
			$price=$params[0];
		}

		if(isset($price)){
        	$users=Users::getUsersByPrice($price);
    
		  require_once (ROOT.'/views/list_all.php');
		  return true;
        }


the code for apartaments:

public static function getUsersByPrice($price){
		$db= Database::getConnection();
		$stmt= $db->prepare("SELECT * FROM flat  WHERE price=:price < :price");

		$stmt->execute([':price'=>$price]);

		$users= $stmt->fetchAll(PDO::FETCH_ASSOC);
        return $users;
	}


What I have tried:

this is the first query, here it display the whole table

$stmt= $db->prepare("SELECT * FROM flat  WHERE price=:price < :price");

		$stmt->execute([':price'=>$price])


The second one i try is this:
$stmt= $db->prepare("SELECT * FROM flat WHERE price=:price = (SELECT MIN (price=:price) FROM flat ) ");


With this query it is displayed only colums id,Area,Complex,City,Price

This is the table:

id	Area	   Complex	    City	      Price
0	 71	       Sarafovo	    Burgas	      550.000
1	 108	   St Vlas	    St Vlas	      47.000
2	 105	   Izgrev	    Burgas	      121.000
3	 58	       Slaveykov	Burgas	      57.000
4	 95	       Slaveykov	Burgas	      82.000
5	 65	       Paradise	    Nesebar	      65.000
6	 109	   Valley	    Sofia	      78.000
7	 45	       Aura	        Sofia	      103.000
8	 168	   Smirnenski	Plovdiv	      91.000
9	 73	       Tomov Plaza	Plovdiv	      47.000
Posted
Updated 15-Dec-22 8:14am
v2

1 solution

Try:
SELECT * FROM flat  WHERE price < :price
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900