Solved

PHP If statement

Posted on 2013-02-01
5
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 83

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

735 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