Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 If statement with query

Author  Topic 

alfaperk
Starting Member

1 Post

Posted - 2013-04-20 : 19:15:04
Could you please help me implement this If statement to the query


$where = array();
$whereclause = '';

if (!empty($mark)) {
$where[] = "a.mark = '$model'";
}
if (!empty($model)) {
$where[] = "a.model = '$mark'";
}
if (!empty($year)) {
$where[] = "a.year = $year";
}
if (count($where > 0)) {
$whereclause = 'WHERE ' . join(' AND ', $where);
}



$result = mysql_query("SELECT * FROM `add_new_car` AS a INNER JOIN `image_add_car` AS b ON

a.id_add_car = b.user_id WHERE (b.user_id, b.id_image_add_car) IN (SELECT user_id, MIN(id_image_add_car)

FROM image_add_car GROUP BY user_id) AND a.mark='$model' and a.model='$mark' and a.year='$year' ORDER BY a.id_add_car");

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-22 : 02:39:18
please post in some mysql forums. this is ms sql server forum and we deal with mostly transact sql.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -