Help creating a query

    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 '[info]'mysql.

    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]."%'";

    Source: http://www.livejournal.com/community/php/317164.html

« Array Value Removal || Understand Error messages »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home