Use a PHP FOR loop in a WHERE SQL Statement -
i want list results ($photostopromote[$i]) of statement within bit of sql query.
at moment statement outputs text list of results, , sql picks 1 of $photostopromote if 1 photo has been selected on previous page. if more 1 photo has been selected statement lists them all, sql not find them , display images.
do need use mysql_real_escape_string before putting sql? how can too?
$photostopromote = $_post['promotephoto']; if(empty($photostopromote)) { echo("<p class=\"error\">you didn't select photos go , start again!"); } else { $n = count($photostopromote); echo("you selected $n photos(s): "); for($i=0; $i < $n; $i++) { echo($photostopromote[$i] . " "); } } $queryuserphotos = mysql_query("select photoid photos photoid='$photostopromote[$i]' , (auth = '5' or auth = '2' or auth = '4') order auth desc") or die("something went wrong...please try again later!"); while($resultuserphotos = mysql_fetch_array($queryuserphotos)){ <img src=\"/$imgpath/$resultuserphotos[photoid].jpg\" alt=\"your photo\"/> }
could try this:
$c = ''; foreach ($photostopromote $p) { $c .= " photoid=$p or "; } $c .= '1=2';//false condition close $c condition never true $q = "select photoid photos ( $c ) , (auth = '5' or auth = '2' or auth = '4') order auth desc"; $queryuserphotos = mysql_query($q) or die("something went wrong...please try again later!");
Comments
Post a Comment