Image

Imagesventhelost wrote in Imagephp 😯confused

Help creating a query

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 Imagemysql.

I have an array of starting letters. I'm trying to select all projects that start with a letter in an array. The array will have at least one letter, possibly more.

Here is the code that's causing me confusion:
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]."%'";