By reading the topic I suppose it sounds rather strange. It is, kind of. W开发者_运维技巧hat I want is to add text in a SQL query by using a for loop. My current code looks like this for the moment:
$sql = mysql_query("UPDATE hon_setups SET hidTop = '"
for ($i = 0; $i < count($selectedSetupTop); $i++) {
echo 'OR imageId = 1 ';
}
"'") or die(mysql_error());
As you may see I want to add (in this example) the text "OR imageId = 1 " until $i is the same value as $selectedSetupTop. The $selectedSetupTop variable is sent from a previous page. The example above is a script page. Tell me if you need better explanation. Thanks in advance!
Ok. So your 'echo' is a fixed string. you'd end building a query that looks like
UPDATE hoN_setups SET hidTop = ' OR imageID = 1 OR imageID = 1 OR imageID = 1'
I'm assuming you want to use some IDs stored in the $selectedSetupTop array, which'd you'd do like this:
$values = implode(',', $selectedSetupTop);
$sql = "UPDATE hon_setups SET hidTop = somevalue WHERE imageID IN ($values);";
mysql_query($sql) or die(mysql_error());
精彩评论