Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP If statement

Posted on 2013-02-01
5
Medium Priority
?
359 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 1200 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 84

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 800 total points
ID: 38846029
you should remove ;   here  $row['question'];
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

963 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