Re: implode()
| From: | Joakim Andersson | Date: | Tue, 26 Nov 2002 19:07:07 +0000 |
| Subject: | Re: implode() | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126152@lists.php.net to get a copy of this message | ||
Jef wrote:
This is how I would do it: <?php $separator = ""; if($image11_name != '') { $sqlUpdate .= $separator . "image11='$image11_name'"; $separator = ", "; } if($image12_name != '') { $sqlUpdate .= $separator . "image12='$image12_name'"; $separator = ", "; } if($textfield11 != '') { $sqlUpdate .= $separator . "textfield11='$textfield11'"; $separator = ", "; } if($textfield12 != '') { $sqlUpdate .= $separator . "textfield12='$textfield12'"; $separator = ", "; } if($textlink11 != '') { $sqlUpdate .= $separator . "textlink11='$textlink11'"; $separator = ", "; } if($textlink12 != '') { $sqlUpdate .= $separator . "textlink12='$textlink12'"; $separator = ", "; } if($sqlUpdate != "") { $query = "UPDATE my_table SET " . $sqlUpdate; // Execute query } else { // Nothing to update... } ?> Regards Joakimimplode() expects an array as the second argument. You're passing astring. Infact with the code you have above I don't see why you don't just tack the comma on the end in the first place: if($image11_name != '') $sqlUpdate .= "image11='$image11_name', ";The reason being the comma at the end of the SQL command will prevent the command from working because SQL will expect another entry. However, your comment about implode expecting an array helps out. Thanks.