Solved

PHP If statement

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 look for a specific file type in a local or remote server directory using PHP.

636 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