empty() not working when mysql is fetching array

Not sure why this isnt working. I'm assuming it's because i am fetching an array but not sure why that would stop it.

Heres the code anyhow;


include ("../database.php");
$result = mysql_query("SELECT * FROM gigs WHERE artisturl='$artistname'");

while($row = mysql_fetch_array($result)){

if (empty($row['gigname'])){echo  '<p2>'.$row['artistname']. 'has not posted any gigs     yet. Check back later.</p2>';}
else {
echo     $row['gigname'].$row['venue'].$row['lineup'].$row['date'].$row['time'].$row['price'].$row['    purchase'].'<br><br>';}}?>


Not sure why this isnt working

You've not stated what your criteria for 'working' are.

Your code doen't make any sense. empty() is not the right function to use here - indeed there is no function which will work here because if there are no matching records then the body of the loop will never execute.

There are lots of ways to deal with the scenario. Here's a simple one:

if (mysql_num_rows($result)) {
   while($row = mysql_fetch_array($result)){
      echo ....
} else {
   echo  '<p2>'.$row['artistname']. 'has not posted any gigs...'

Empty has unexpected results with strings, i'd suggest you read this article.

For example :

    $mystring = '0';
if (empty($mystring)) {
    // this code will run
    // what if this was code to take action when $mystring is undefined?

So make sure gigname is not 0.

Consider using is_null($row['gigname']))

Need Your Help

Android: how to tell if a view is scrolling

android scroll webview

in iPhone, this would be simple---each view has a scrollViewDidScroll method. I am trying to find the equivalent in Android.

Offline Map using ArcGIS android SDK

android android-studio maps arcgis

I'm trying to develop an Offline maps application using ArcGis android sdk. Followed the tutorials from the ArcGis website.Since it is an Offline Maps Applicaion, I am testing it without an internet