what i'm basically trying to do is make a 'thumbs up' appear if the user scores >= to 2 and shows a 'thumbs down' if the user scores < 2
Here is the code i tried to use..
<?php
//Recieves form..Form ID
$fid = $_GET['id'];
//Recieves answers
$answer1= $_POST['answerOne'];
$answer2= $_POST['answerTwo'];
$answer3= $_POST['answerThree'];
$score=0;
?>
<?php //Gets thumbs up if did well, gets thumbs down if not so good
if ($score>=2){
echo "<center><img src='Images/thumbsup.png' height='295' width='295' /> </center>";
}
elseif ($score<2) {
echo "<center><img src='Images/thumbsdown.png' height='295' width='295' /> </center>";
}
?>
<body>
<!--Answers for Quiz 1-->
<?php
if ($fid == 1){
if ($answer1 == "B") {$score++;}
if ($answer2 == "B") {$score++;}
if ($answer3 == "A") {$score++;}
}
?>
<?php
if ($fid == 1){
echo "
<p id='YourScore'> Your score is: </p>
<p id='YourScore'>$score/3 correct answered </p>";}
?>
What happens is that it always show up 'thumbs down'. I think its because $score is equals to 0 and what its NOT doing is using the incremented value after adding the score as the value to use to define whether to give a thumbs up or down.
Any help would be appreciated.
As mentioned in my comment: you calculate score after your thumbs, so turn those around:
<?php
//Recieves form..Form ID
$fid = $_GET['id'];
//Recieves answers
$answer1= $_POST['answerOne'];
$answer2= $_POST['answerTwo'];
$answer3= $_POST['answerThree'];
$score=0;
?>
<body>
<div id="Wrapper">
<div id="Container">
<!--Answers for Quiz 1-->
<?php
if ($fid == 1) {
if ($answer1 == "B") {$score++;}
if ($answer2 == "B") {$score++;}
if ($answer3 == "A") {$score++;}
}
?>
<?php
//Gets thumbs up if did well, gets thumbs down if not so good
if ($score >= 2) {
echo "<img src='Images/thumbsup.png' height='295' width='295' /> ";
}
elseif ($score < 2) {
echo "<img src='Images/thumbsdown.png' height='295' width='295' /> ";
}
if ($fid == 1) {
echo "<p id='YourScore'> Your score is: </p>
<p id='YourScore'>$score/3 correct answered </p>";
}
?>
Thats because you aren't checking the answers therefore the score will always be 0 and elseif ($score<2) will always be true.
You have to check if the answers where right BEFORE printing the 'thumbs'
Related
I have this loop at the same it will count the output:
while ($wp_query->have_posts()) : $wp_query->the_post(); $current++; $current2++;
Then to call the proper html class I need this for my design:
<div class="span4 <?php if($current == 0) { echo 'first'; } elseif($current == 1) { echo 'second'; } elseif($current == 2) { echo 'first'; } elseif($current == 3) { echo 'second'; } ?>" id="<? echo $current; ?>">
The $count starts from 0 and $count2 from 1. The output should be like this: if 0=first, 1=second, 2=first, 3=second and so forth. How can I make this expression shorter with unlimited number of $count? I hope my question is clear. Thank you for those who will help me here.
If I understand what you are asking here, I think you want to alternate your divs with'first' and 'second' classes?
As such, you can use the % modulo operator (see http://php.net/manual/en/internals2.opcodes.mod.php)
<div class="span4 <?php echo ($current % 2 === 0 ? 'first' : 'second'); ?>" id="<? echo $current; ?>">
If you are just using these class names for alternating CSS styles there is a much elegant way to do this using CSS3
Your HTML
<div class="span4" id="<? echo $current; ?>">
And in your css file
.span4:nth-child(even) {background: #CCC}
.span4:nth-child(odd) {background: #FFF}
else for a PHP solution the answer by Liam Wiltshire should work good.
source: CSS even and odd rules examples
So you could use mod - best to use the full<?php tag for WordPress if that is what it is.
php test if number is odd or even
// set up the html clips
if($current % 2 == 0){
$html_clips = 'first';
}else{
$html_clips = 'second';
}
if($current == 0) $html_clips = 'first';
<div class="span4 <?php echo $html_clips ?>" id="<?php echo $current; ?>">
try this way
<div class="span4
<?php if ($curent%2 == 0){ echo 'first'; }
else {echo 'second';}?> id="<? echo $current; ?>">
Having a small issue here but cannot figure out where I have gone wrong. I have the following code which should show an image depending on the condition but instead it shows the HTML in the browser
if ($this->id_status == 2)
{
$this->id_status = "<img src='../_lib/img/gray_dot.png' />";
}
elseif ($this->id_status == 1)
{
$this->id_status = "<img src='../_lib/img/green_dot.png' />";
}
elseif ($this->id_status == 3)
{
$this->id_status = "<img src='../_lib/img/orange_dot.png' />";
}
Can anyone help?
try this:
<?php
if ($this->id_status == 2)
{
?>
<img src='../_lib/img/gray_dot.png' />
<?php
}
elseif ($this->id_status == 1)
{
?>
<img src='../_lib/img/green_dot.png' />
<?php
}
elseif ($this->id_status == 3)
{
?>
<img src='../_lib/img/orange_dot.png' />
<?php
}
?>
I have tried
if ($row_products['psText'] != empty) {
and
if (!empty($row_products['psText'])) {
and
if (!is_null($row_products['psText'])) {
None of them work. However, if I echo out the echo $row_products['psText'], it has texts in there. Am I missing something here?
Okay, I'm updating my code. Below is the whole block of code. Perhaps my logic is wrong and not the code.
<?php do { ?>
<?php if($row_products['psLeft'] != ""){ ?>
<div id="left"><?php echo $row_products['psLeft']; ?></div>
<?php } if($row_products['psCenter'] != ""){ ?>
<div id="center"><?php echo $row_products['psCenter']; ?></div>
<? } if($row_products['psRight'] != ""){ ?>
<div id="right"><?php echo $row_products['psRight']; ?></div>
<? } if($row_products['psText'] != NULL && $row_products['psText'] != '' && !empty($row_products['psText'])){?>
<p>
<?php echo $row_products['psText']; ?>
</p>
<?php } else {echo 'Outside texts.'.$row_products['psText'];}?>
<?php } while ($row_products = mysql_fetch_assoc($products)); ?>
Try this
if ($row_products['psText'] != '') {
OR
if (strlen($row_products['psText']) !=0) {
OR
if(!empty($row_products['psText']))
I hope this helps you!!
You might try:
if ($row_products['psText'] != "") {
maybe following works:
if($row_products['psText'] != NULL && $row_products['psText'] != "" && !empty($row_products['psText'])){
This while loop is supposed to continue until the end of the array or until counter reaches 6, what am I doing wrong here?
while($row = mysql_fetch_array($resultSet, MYSQL_ASSOC) && ($counter < 6))
{
?>
<?php echo $row['Item_NAME'] ?>
<img style="width:250px; height:250px;" src="<?php {echo "{$row['Item_IMAGE']}";} ?>">
<?php $counter = $counter + 1;
?>
<?php
}
Works without the && ($counter < 6)but shows the wrong number of images, adding this will show the correct number of boxes (where the images should be) but not retrieve the images or names from the array.
Thanks for any help.
Couldn't you just use break; inside, when the second condition isn't true anymore?
while($row = mysql_fetch_array($resultSet, MYSQL_ASSOC))
{
if($counter > 5){
break;
}
?>
<?php echo $row['Item_NAME'] ?>
<img style="width:250px; height:250px;" src="<?php {echo "{$row['Item_IMAGE']}";} ?>">
<?php $counter = $counter + 1;
?>
<?php
}
I am using this code for Condtion but I dont know why the condtion is going False
<tr
<?php if ($LevelName['Status'] == 'Yes') { ?>
style="background:#DCFEB7"
<?php } ?>
<?php elseif (strtotime(date('Y-m-d h:i')) > strtotime($LevelName['ReportTime'])) { ?>
style="background:red"
<?php } ?>
<?php else { ?>
style="background:orange"
<?php } ?>
>
I don't know why the backgound color not going to Red
getting this result in condition:
(Todat Date)392291420 > (DB Date)1392336360