**SOLVED** Display table result based on its value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

**SOLVED** Display table result based on its value

Post by mikes1471 »

Hi Guys

I'm aware that one of the first lessons in PHP is this:

Code: Select all

if ($msgread=="1")
  echo "Yes";
else
  echo "No";
I'm not sure though, how to display the result in various parts of a webpage, have tried

Code: Select all

$status=$msgread;
if ($msgread=="1")
  $status=="The message has been read";
else
  $status=="The message has not been read";
And then just echo $status wherever required in the webpage
Please help!
Last edited by mikes1471 on Fri Dec 11, 2009 9:38 pm, edited 1 time in total.
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Display table result based on its value

Post by AlanG »

mikes1471 wrote:

Code: Select all

$status=$msgread;
if ($msgread=="1")
  $status=="The message has been read";
else
  $status=="The message has not been read";
Your getting your operators messed up.

$varOne = $varTwo; // This basically means "Assign the value in $varTwo to $varOne"
$varOne == $varTwo; // This basically means "Does the value of $varOne equal the value of $varTwo"

In your code your mixing them up, it should be:

Code: Select all

$status = $msgread;
if($msgread == "1") {
    $status = "The message has been read";
}
else {
    $status = "The message has not been read";
}
 
echo $status;
You should also space your code up abit more so it's easier to read.
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

Re: Display table result based on its value

Post by mikes1471 »

AlanG wrote:

Code: Select all

$status = $msgread;
if($msgread == "1") {
    $status = "The message has been read";
}
else {
    $status = "The message has not been read";
}
 
echo $status;

Although this seems correct, Ive tried it and what were a mixture of '0' and '1' now appear as The message has not been read, is there a a reason why the message The message has been read would not appear where the 1's used to?
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

Re: Display table result based on its value

Post by mikes1471 »

Its all fine now, I just changed the position of the code, thanks for the help
Post Reply