Hello am trying to count how many rows are in location column where there names include any of the names which are in the predefined $uk_array.
mysql prints out that I don’t have any value in my column “there are ()” that matches a name from the array although there is one “Dublin, Ireland”.
Here is the code:
<?php
include'connect.php';
$uk_array = array('Liverpool','London','London UK','UK','London',
'Dublin, Ireland','Manchester','Norwich','United Kingdom','Norwich','Duplin','England','ENGLAND',
'united kingdom');
$string = '';
foreach($uk_array as $term=>$i) {
$string = $string."location LIKE '%".$i."%' AND";
}
$string = substr($string, 0, -5);
$query="SELECT COUNT(location) as location FROM tweets WHERE $string";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "There are ". $row['location']."";
}
?>
You should be doing
Switch the AND operator with the OR operator, otherwise the field has to contain all of the values in uk_array.
Also, you have a typo – Duplin?
Edit: More errors