Thanks for all the help, that has really helped me understand the concept. I've tried all the suggestions and they work great when constructing a complete query, but if nested inside or at the end of a larger mysql query the while loop does work. Maybe if I show more of the script, you someone can suggest how to improve it?
$sql = "SELECT count(row) as cnt FROM table WHERE column LIKE '%a%' AND column NOT LIKE '%b%' AND column NOT LIKE '%c%' AND column NOT LIKE '%d%'";
//a,b,c,d are specific to this query
//$var_array contains global values to be used in several queries
while($data = array_pop($var_array)) {
$sql .= " AND column NOT LIKE '%$data%'";
}
//database connection here
$result = mysql_query ($sql);
while ($row = mysql_fetch_array($result)) {
$end_value = $row["cnt"];
}
I am trying to count occurances of certain strings in a db column. Could this be done in a more efficient way?
Thanks once again!