Question about SQL query!

Discussion in 'PHP' started by Kyriakos, May 19, 2009.

  1. #1
    hi,

    i have an SQL string:
    <?php
    $sql = mysql_query("select * from products where category='$cat' and manufact='man' and status=1 order by price")
    ?>
    PHP:
    i want when the man <> "" to have this statement in the SQL string and manufact='"&man&"' but when man = "" i don't want to have this statement.

    can anybody tell me what can i do?
     
    Kyriakos, May 19, 2009 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    try this:
    
    $sql=($man!='')?mysql_query("select * from products where category='$cat' and manufact='$man' and status=1 order by price"):mysql_query("select * from products where category='$cat' and status=1 order by price");
    
    PHP:
    I guess you mean var $man
    Regards :)
     
    koko5, May 20, 2009 IP
  3. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    isn't another way without SQL replacement? i want (if possible) to write the replacement inside the SQL Query
     
    Kyriakos, May 20, 2009 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    $sql = mysql_query("select * from products where category='$cat' and status=1 and IF('$man'='',1,manufact='$man') order by price");
    PHP:
    :cool:
     
    koko5, May 20, 2009 IP