Page 1 of 1
**SOLVED** Display table result based on its value
Posted: Fri Dec 11, 2009 6:43 pm
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!
Re: Display table result based on its value
Posted: Fri Dec 11, 2009 7:19 pm
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.
Re: Display table result based on its value
Posted: Fri Dec 11, 2009 7:45 pm
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?
Re: Display table result based on its value
Posted: Fri Dec 11, 2009 9:37 pm
by mikes1471
Its all fine now, I just changed the position of the code, thanks for the help