I'm trying to select all the rows from my database, where 'street' is LIKE the contents from an array ($streets).
Here's what I have...
#TEXT AREA INPUT = $streets
$sql = "SELECT * FROM `data` WHERE `street` LIKE '%".implode("%' OR `street` LIKE '%",$streets)."%'";
echo $sql;
$result = mysqli_query($con,$sql) or die(mysql_error());
$totalitems1 = mysqli_num_rows($result);
echo $totalitems1 . "<br>";
while($row = mysqli_fetch_array($result))
{
echo $row['street']. "<br>";
}
the varible $streets is exploded from a text area input, each value on a new line.
When I process this using PHP, only the rows that are LIKE the last 'OR' are returned .. (The last line in the text area). But when I copy and paste the generated SQL into PHPMYADMIN, it returns ALL the data, as expected.
What am I missing here? Thanks.
mysqli_fetch_assoc()
instead ofmysqli_fetch_array()
– Fred -ii- Feb 19 at 23:32mysqli_query
with anmysql_*
functionmysql_error
which will result in not showing the actual error message. – Fred -ii- Feb 19 at 23:46