Re: [PHP4BETA] if in an mysql insert statement
| From: | Bram de Kruijff | Date: | Mon, 14 Feb 2000 12:01:11 +0000 |
| Subject: | Re: [PHP4BETA] if in an mysql insert statement | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10241@lists.php.net to get a copy of this message | ||
> Is there anyway to have an if statement in the mysql insert function??
> I looked in the manual and it said if(test, value1, value2)
> Now if test is true value1 will occur if not value2 will occur.. this is all grat makes total
> sense... but what if i want more than one if statement in a single entry...
I don't know wether this should or could work, but WHY(????!!!!) would
you consider using this when you have all the controlstructures you'll
ever need right there in this great language called PHP!
Using more then one language at a time is bad practice!..... well in
my book anyway :))
So how about something like
<?php
#determine uncertain values
if ($circle) {
$value = 1;
} else {
if (....) { #or whatever fits :)
}
}
#construct query
$my_query = " insert
into my_table (my_id, my_blah)
values ('0','".$value."')";
#do query
mysql_query($my_query,$db);
?>
Now it works, it's easy to read, easy to understand and
easy to validate!
cheers!
Bram
>
> I have this statement:
>
> mysql_query("INSERT INTO subscribers
> (first, last, address, city, state, country, zip, phone, email, sourceSite, referer, entryTime,
> emailMe, subscribeto) VALUES('$name','$surname', '$address',
> '$city', '$state', '$country','$zip', '$phone',
> trim('$email'), 'activeassets', '$refer', '$currentDate',
> '1', 'if ($circle,1, ), if ($newsclub,33, )')'")
>
> See... what i want for the final insert is for : if $circle is defined then insert '
> ,1,' if newsclub is defined insert ',33,' if they are both defined insert
> '1,33,'
>
> I dont really know how to do this so if anyone could help that would be great.
>
> Mikey T
>
>
>
>