Solved

PHP If statement

Posted on 2013-02-01
5
320 Views
Last Modified: 2013-02-01
Hi guys,

I'd like to setup a simple php statment that checks to see if the value of variable is empty and if some displays one event and if it has a value then another event is displayed.

The variable is called $row['question'] and if its empty I want to display this :

<img src="change_question_little_button2.jpg" alt="Pulpit rock" width="60" height="50">

If it has a value I want to display this:

Your current value is...<?php echo $row['question']; ?>  <img src="change_question_little_button.jpg" alt="Pulpit rock" width="60" height="50">

Thank you very much for your assistance,

D
0
Comment
Question by:TLN_CANADA
5 Comments
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 300 total points
ID: 38845814
<?php
if (!empty($row['question']))
{
    echo 'Your current value is...' . $row['question']; . ' <img src="change_question_little_button.jpg" alt="Pulpit rock" width="60" height="50">';
}
else
{
    echo '<img src="change_question_little_button2.jpg" alt="Pulpit rock" width="60" height="50">';
} 
?>

Open in new window



Cd&
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 38845816
$row['question'] sounds like it is coming from your database.  I would probably do this:

<?php 
$question = $row['question'];
if($question != "") echo "Your current value is...$question";
?>  
<img src="change_question_little_button.jpg" alt="Pulpit rock" width="60" height="50">

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 38845824
Thanks cd,

I tried your code but it gives an error on this line:

    echo 'Your current value is...' . $row['question']; . ' <img src="change_question_little_button.jpg" alt="Pulpit rock" width="60" height="50">';

Parse error: syntax error, unexpected '.' in /home/clear555/public_html/dyadmenu_beforevanprogrammer.php on line 143
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 38846026
try this,

echo 'Your current value is...' . $row['question'] . ' <img src="change_question_little_button.jpg" alt="Pulpit rock" width="60" height="50">';
0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 200 total points
ID: 38846029
you should remove ;   here  $row['question'];
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now