Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF Statement 1

Status
Not open for further replies.

FireGeek21

Technical User
Dec 12, 2007
218
0
0
US
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!!!

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)
 
?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
 
Row is for accessing the data in a mysql database.

The inside IF statement is not working.

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)
 
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)
 
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
 
Hi

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

Feherke.
feherke.ga
 
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)
 
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.

PHP:
<?php
				if (([b][COLOR=#A40000]$[/color][/b]row['level'])[b][COLOR=#A40000]==[/color][/b]"CCMedic") {
					[b][COLOR=#A40000]echo[/color][/b] '<div><a><img src="/includes/images/red.png" alt=""></a></div>'[b][COLOR=#A40000];[/color][/b]
				} elseif (([b][COLOR=#A40000]$[/color][/b]row['level'])[b][COLOR=#A40000]==[/color][/b]"Medic") {
					[b][COLOR=#A40000]echo[/color][/b] '<div><a><img src="/includes/images/blue.png" alt=""></a></div>'[b][COLOR=#A40000];[/color][/b]
				} else {
					[b][COLOR=#A40000]echo[/color][/b] '<div><a><img src="/includes/images/gray.png" alt=""></a></div>'[b][COLOR=#A40000];[/color][/b]
				}
			?>
 
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
 
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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top