This is driving me nuts I am so close. Please help!!
I made a web page with a few drop down boxes. some of which have a selection of ALL.
I have a js array like
sitesArray = [1,2,3,4,5,6]
I turn the js array into a comma delimited string: var sitesStr = sitesArray.join(',')
and I use jquery to post the string to PHP.
On the PHP side:
I grab the post variable and turn it into a php array:
$siteArray = explode(',',$_POST['sitesStr']);
This is to be used in the where clause of a sql query.
Calling one variable from the array works.
$position = "pl.position = '" . $siteArray[5] . "' ";
Output is 6
Trying to append string to a variable behaves unexpectedly.
PHP Code:
<?php
$siteArray = explode(',',$_POST['sitesStr']);
$position = sites($siteArray);
function sites($siteArray) {
$position = "( ";
for ($i=0; $i > count($siteArray); $i++) {
if ($i == 0) {
$position .= "pl.position = '$siteArray[$i]' ";
} else {
$position .= "or pl.position = '$siteArray[$i]' ";
}
}
$position .= " )";
return $position;
}
?>
the function returns ( ) like it completely ignores the appending of the for loop!!!
Where did I go wrong???
Thanks
Bookmarks