Forum Moderators: coopster
My code is like this:
$query = "SELECT DISTINCT name FROM `atable` WHERE name LIKE '%john%'";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result);
while ($row = mysql_fetch_array($result)) {
echo $row["name"];
}
This should all be fine I think, however for certain records no data is returned - i.e. selecting records for '%john%' works but doesn't return anything at all for '%jim%'. Also if I remove DISTINCT then I do get a list of records...
If I run the query code directly with sql queries it always returns results so I guess the problem must be with my PHP somewhere.
Can anyone offer any suggestions as I've just about run out of ideas with this one.
Andy
$query = "SELECT DISTINCT name FROM `atable` WHERE name LIKE '%john%'";
$result = mysql_query($query) or die (mysql_error());
//$row = mysql_fetch_array($result);
while ($row = mysql_fetch_array($result)) {
echo $row["name"];
}
Unfortunately I still have the problem of no results returned for certain queries.
If I add echo $row["name"]; before the while section then I do get a result, but I can't work out why I then get nothing after "while ($row = mysql_fetch_array($result))"
In any case, many thanks!