×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

IF Statement

IF Statement

IF Statement

(OP)
HI,

Beginner here... I may have some syntax off a bit. Looking for some help here. I am adding a colored circle depending on the "level" in a database. The code before this connects to the database. Everything worked fine until I added the "IF" statement for the colored circles. Where did I go wrong???

Thanks for the help!!!

CODE --> php

<?php while($row = mysql_fetch_array($result)):?>
	<div>
		<div><a target="_blank" class="doc" href="Medications/<?=htmlspecialchars($row['medication'])?>.pdf"><?=htmlspecialchars($row['medication'])?></a></div>
			<?php
				if ((?row['level'])="CCMedic") {
					'<div><a><img src="/includes/images/red.png" alt=""></a></div>'
				} elseif ((?row['level'])="Medic") {
					'<div><a><img src="/includes/images/blue.png" alt=""></a></div>'
				} else {
					'<div><a><img src="/includes/images/gray.png" alt=""></a></div>'
				}
			?>
	</div>
<?php endwhile;?> 

FireGeek
(currently using Crystal Reports XI with Lawson 9.01)

RE: IF Statement

?row ???

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: IF Statement

(OP)
Row is for accessing the data in a mysql database.

The inside IF statement is not working.

CODE --> php

<?php
				if ((?row['level'])="CCMedic") {
					'<div><a><img src="/includes/images/red.png" alt=""></a></div>'
				} elseif ((?row['level'])="Medic") {
					'<div><a><img src="/includes/images/blue.png" alt=""></a></div>'
				} else {
					'<div><a><img src="/includes/images/gray.png" alt=""></a></div>'
				}
			?> 

FireGeek
(currently using Crystal Reports XI with Lawson 9.01)

RE: IF Statement

(OP)
If I take out the IF statement that is not working, I do get a list of medications in mysql database as links to .pdf files.

I am trying to add a red or blue circle .png image after each medication name based on a "level" entered in the [level] field in mysql database.

Thanks for looking Chris - I appreciate your time!

FireGeek21

FireGeek
(currently using Crystal Reports XI with Lawson 9.01)

RE: IF Statement

Yes, I know what $row would mean ... I'm simply wondering what ?row is supposed to be doing? As it's not a PHP syntax I am familiar with.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: IF Statement

Hi

Beside that, you may wish to involve $row['level'] in equality checks ( == ), not assignments ( = ).

Feherke.
feherke.ga

RE: IF Statement

(OP)
Chris, if ?row is the wrong syntax for PHP, what is the correct way of doing it?

Feherke, thanks for your response. I will try the equality ( == ) and get back this evening.

FireGeek

FireGeek
(currently using Crystal Reports XI with Lawson 9.01)

RE: IF Statement

Also with in if blocks you just have quoted strings that aren't getting assigned to any variables or output. There is also no line termination character ; following those lines.

CODE --> PHP

<?php
				if (($row['level'])=="CCMedic") {
					echo '<div><a><img src="/includes/images/red.png" alt=""></a></div>';
				} elseif (($row['level'])=="Medic") {
					echo '<div><a><img src="/includes/images/blue.png" alt=""></a></div>';
				} else {
					echo '<div><a><img src="/includes/images/gray.png" alt=""></a></div>';
				}
			?> 

RE: IF Statement

Quote:

Chris, if ?row is the wrong syntax for PHP, what is the correct way of doing it?

How you have it when initialising the variable and the loop

while($row = mysql_fetch_array($result)):?>
_____^____________________^_______

PHP variable names start with a $

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: IF Statement

(OP)
Awesome! It works. Switched out the ? for $ - typo I think. Added the == and echo and ;.

Now on to the next problem, a list of 2 columns because this one is too long. :)

Thanks again for everyone's help!

FireGeek
(currently using Crystal Reports XI with Lawson 9.01)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close