SQL Server Forums
Profile | Register | 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
 New Topic  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

52325 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  
 New 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.06 seconds. Powered By: Snitz Forums 2000