0

I am a beginner when it comes to php.... I have the following:

I am not sure if it is my if statement expressed wrong or just at the wrong place. I want it not to show the records when the companyname == the businessname! Please advise?

if (mysql_num_rows($sql) > 0  && **($row['companyname'] == $user_data['businessname'])** ) 
{            

while ($row = mysql_fetch_array($sql)){
   if (($employed =='1')){


    echo '<h4>  ID                  :  '.$row['idnumber'] ;
    echo '<br>  First Name          :  '.$row['firstname'];
    echo '<br>  Last Name           :  '.$row['lastname'];
    echo '<br>  Reference 1         :  '.$row['ref1'];
    echo '<br>  Reference 2         :  '.$row['ref2'];
    echo '<br>  Reference 3         :  '.$row['ref3'];
    echo '<br>  Gender              :  '.$row['gender'];
    echo '<br>  Company             :  '.$row['companyname'];
    echo ' </h4>';


    echo '<br />';
    echo '<h2>Some Additional Options</h2>';
    echo '<br />';
  include 'includes/admenu.php';
    }

}       
}

else
 {
print ("$XX");
}
4

1 回答 1

4

The $row variable doesn't exist outside your loop, so it's pointless trying to use it in the if statement. You need to move it inside the loop, like so:

while ($row = mysql_fetch_array($sql))
{
    if ( ($employed =='1') && ($row['companyname'] == $user_data['businessname']) ) 
    {
        // code ...
    }
}

I want it not to show the records when the companyname == the businessname!Move the statement inside your loop:

I'm not actually sure if you're trying to display when companyname == the businessname or companyname != the businessname. Either way, change your if condition accordingly and it should work.

于 2013-09-19T23:02:34.030 回答