Jump to content

If Statement not working?


lalnfl
 Share

Recommended Posts

$sql_my_workers = mysql_query("SELECT * FROM Worker WHERE mem_id='$id'");

$my_workers_result = mysql_num_rows($sql_my_workers);

while($get_my_workers = mysql_fetch_array($sql_my_workers)){

 

$my_worker_firstname = $get_my_workers['firstname'];

$my_worker_lastname = $get_my_workers['lastname'];

$my_worker_age = $get_my_workers['age'];

$my_worker_yearspro = $get_my_workers['yearspro'];

$my_worker_promotion = $get_my_workers['promotion'];

 

 

 

if ($my_workers_result < 1){

 

$my_workers = "

 

<p class='text' align='center'>You have not created any workers.</p>

 

";

 

}

 

else {

 

$my_workers .= "

 

<div class='worker_name' align='center'>

 

<p class='text3' style='font-weight: bold; '>Name</p>

<p class='text3'>$my_worker_firstname $my_worker_lastname</p>

 

</div>

 

<div class='worker_age' align='center'>

 

<p class='text3' style='font-weight: bold; '>Age</p>

<p class='text3'>$my_worker_age</p>

 

</div>

 

<div class='worker_promo' align='center'>

 

<p class='text3' style='font-weight: bold; '>Promotion</p>

<p class='text3'>$my_worker_promotion</p>

 

</div>

 

<div class='worker_contract' align='center'>

 

<p class='text3' style='font-weight: bold; '>Contract</p>

<p class='text3'>-</p>

 

</div>

 

<div class='worker_yearspro' align='center'>

 

<p class='text3' style='font-weight: bold; '>Years Pro</p>

<p class='text3'>$my_worker_yearspro</p>

 

</div>

 

<div class='line'></div>";

 

}

 

}

 

// connect to the database

 

include_once ("Scripts/mysql_db_connect.php");

 

// get free agents

 

$sql_free_agents = mysql_query("SELECT * FROM Worker WHERE mem_id!='$id'");

$free_agents_result = mysql_num_rows($sql_free_agents);

while($get_free_agents = mysql_fetch_array($sql_free_agents)){

 

$free_agent_firstname = $get_free_agents['firstname'];

$free_agent_lastname = $get_free_agents['lastname'];

$free_agent_age = $get_free_agents['age'];

$free_agent_yearspro = $get_free_agents['yearspro'];

 

if ($free_agents_result < 1){

 

$free_agents = "<p class='text'>There are no free agents.</p>";

 

}

 

else {

 

$free_agents .= "<div class='fa_name' align='center'>

 

<p class='text3' style='font-weight: bold; '>Name</p>

<p class='text3'>$free_agent_firstname $free_agent_lastname</p>

 

</div>

 

<div class='fa_age' align='center'>

 

<p class='text3' style='font-weight: bold; '>Age</p>

<p class='text3'>$free_agent_age</p>

 

</div>

 

<div class='fa_yearspro' align='center'>

 

<p class='text3' style='font-weight: bold; '>Years Pro</p>

<p class='text3'>$free_agent_yearspro</p>

 

</div>

 

<div class='fa_previouspromo' align='center'>

 

<p class='text3' style='font-weight: bold; '>Previous Promotion</p>

<p class='text3'>-</p>

 

</div>

 

<div class='fa_reasonleftpromo' align='center'>

 

<p class='text3' style='font-weight: bold; '>Reason for Leaving</p>

<p class='text3'>-</p>

 

</div>

 

<div class='fa_salary' align='center'>

 

<p class='text3' style='font-weight: bold; '>Salary</p>

<p class='text3'>-</p>

 

</div>

 

<div class='line'></div>";

 

}

 

}

 

When I do the if < 1 statement, it comes back blank. The if $my_workers_result comes back as showing 0. So it should do that if statement, but yet it doesn't, its just blank. What am I doing wrong?

Link to comment
Share on other sites

Your "if" should be outside the "while".  Because the "while" will never get to run if there are no results, it will just get skipped right away.

 

Then inside the while you will have no if, you will just have the code that is supposed to run for each row (which is currently in the "else")

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.