Results 1 to 5 of 5

Thread: Please help with this mysql script

  1. #1
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default Please help with this mysql script

    I am trying to get a mysql script to evaluate a piece of data then assign
    a value base on the result here is what i have so far:

    Code:
    for($i=0;$i<=$x;$i++){
    $addmerchants = "insert into myp_compare_merchants_cmt 
    (idcmr_cmt,idmrt_cmt,value_cmt) values ('$id_cmr',
    '$merchantid[$i]','if($merchantid[$i]<>0,'1','0')')";
    $addmerchants = mysql_query($addmerchants) or die(mysql_error());
    }
    
    everything works except this part:
    'if($merchantid[$i]<>0,'1','0')'
    Any idea how to do this you all. Thanks in advance.
    "...men are that they might have joy."
    Nephi

  2. #2
    Join Date
    Jan 2007
    Posts
    164
    Rep Power
    18

    Default

    you can use a variable

    e.g. $value = if($merchantid[$i]<>0,'1','0');

    and then add $value to your sql statement

  3. #3
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    ok that looks like it can work. Thanks a million.
    "...men are that they might have joy."
    Nephi

  4. #4
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default

    plus thats just a nasty way to code. PHP only evaluates variables in strings. It won't see the IF statement.

  5. #5
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Default

    Quote Originally Posted by hassanvoyeau View Post
    you can use a variable

    e.g. $value = if($merchantid[$i]<>0,'1','0');

    and then add $value to your sql statement
    This was what I had in mind also, because sql don't do such evaluation.
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •