Date: 07/11/05 (PHP Community) Keywords: php, mysql, sql I need some help with a query I'm trying to create to send to MySQL. The problems are on the PHP side, so I'm posting here rather than at mysql. foreach ($startlet as $let){ $sql.=" $projectcolumn[title] LIKE '".$let."%'"; } I need to put an OR in there at the end of every line but the last. Is there an easy way to do this, or am I going to need to get the length of the array, then iterate some number and compare? I'm fine with a different control structure, but I couldn't find anything that would easily and simply do what I want. Is there one, or am I just going to have to be satisfied with complex? Edit: Never mind Figured I could do it this way. Maybe not so pretty, but functional. $i=0; while ($i<(count($startlet)-1)){ $sql.=" $projectcolumn[title] LIKE '".$startlet[$i]."%' OR"; $i++; } $sql.=" $projectcolumn[title] LIKE '".$startlet[$i]."%'"; Source: http://www.livejournal.com/community/php/317164.html
|