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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 If statement with query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 04/20/2013 :  19:15:04  Show Profile  Reply with Quote
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");

Very Important crosS Applying yaK Herder

52326 Posts

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

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000