Solved

PHP If statement

Posted on 2013-02-01
5
326 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 …

910 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

21 Experts available now in Live!

Get 1:1 Help Now