I am trying to get a 0 result from this foreach loop but it just stays blank. However it does execute the else if part.
I just want to display entries from a database. If there is no entry I just want a plain 0.
$entries = array();
$sql = "SELECT `id` FROM `events` where creator_id='$id' ORDER BY `id` DESC
LIMIT 1";
$query = mysql_query($sql);
while(($row = mysql_fetch_assoc($query)) !== false)
{
$entries[] = $row['id'];
}
$value1 = "0";
foreach($entries as $entry)
{
if ($entry == false)
{
echo "0";
}
else
if($entry > $value1)
{
echo "$entry";
}
}
what might the problem be here?
Try this:
Note that this may still display nothing if everything in $entry is <= $value1. You may want to move that logic to your SQL statement, depending on exactly what you are trying to do.