0
Engaged
,
/t5/dreamweaver-discussions/php-if-else-help-please/td-p/709256
Jan 17, 2007
Jan 17, 2007
Copy link to clipboard
Copied
I have to admit that this is the first time I have tried
conditional statements and am struggling a bit although I think I'm
getting closer.
I have a dynamic table from a test recordset in which there are only 4 records.
I am trying to get the layout cell to alter colour depending on the contactnt of that cell.
Here is where I am so far...
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>TYPE</td>
</tr>
<?php do { ?>
<tr>
<?php if ($row_Recordset1['NOTETYPE'] ="NOTE")?><td bgcolor="#CCCCCC"><?php echo $row_Recordset1['NOTETYPE']; ?>
<?php elseif ($row_Recordset1['NOTETYPE'] ="Action")?><td bgcolor="#00FFCC"><?php echo $row_Recordset1['NOTETYPE']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
Firstly, it seem to create another layout cell to the right of the first (not intended) and it doesn't like the elseif.
What am I doing wrong - does it need a loop?
I have a dynamic table from a test recordset in which there are only 4 records.
I am trying to get the layout cell to alter colour depending on the contactnt of that cell.
Here is where I am so far...
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>TYPE</td>
</tr>
<?php do { ?>
<tr>
<?php if ($row_Recordset1['NOTETYPE'] ="NOTE")?><td bgcolor="#CCCCCC"><?php echo $row_Recordset1['NOTETYPE']; ?>
<?php elseif ($row_Recordset1['NOTETYPE'] ="Action")?><td bgcolor="#00FFCC"><?php echo $row_Recordset1['NOTETYPE']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
Firstly, it seem to create another layout cell to the right of the first (not intended) and it doesn't like the elseif.
What am I doing wrong - does it need a loop?
TOPICS
Server side applications
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
LEGEND
,
Jan 17, 2007
Jan 17, 2007
RichardODreamweaver wrote:
> <?php if ($row_Recordset1['NOTETYPE'] ="NOTE")?><td
<?php if ($row_Recordset1['NOTETYPE'] == "NOTE")?><td
Two equals signs, not one.
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
> <?php if ($row_Recordset1['NOTETYPE'] ="NOTE")?><td
<?php if ($row_Recordset1['NOTETYPE'] == "NOTE")?><td
Two equals signs, not one.
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
LEGEND
,
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709257#M194065
Jan 17, 2007
Jan 17, 2007
Copy link to clipboard
Copied
Should be:
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>TYPE</td>
</tr>
<?php do { ?>
<tr>
<?php if ($row_Recordset1['NOTETYPE'] ="NOTE") { ?>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['NOTETYPE']; ?></td>
<?php } elseif ($row_Recordset1['NOTETYPE'] ="Action") { ?>
<td bgcolor="#00FFCC"><?php echo $row_Recordset1['NOTETYPE']; ?></td>
<?php } ?>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
You were missing a closing </td> tag on the first table cell and you need to
use braces for an if statement eg
if($variable == $value){
}elseif($variable == $something_else) {
}
--
Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>TYPE</td>
</tr>
<?php do { ?>
<tr>
<?php if ($row_Recordset1['NOTETYPE'] ="NOTE") { ?>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['NOTETYPE']; ?></td>
<?php } elseif ($row_Recordset1['NOTETYPE'] ="Action") { ?>
<td bgcolor="#00FFCC"><?php echo $row_Recordset1['NOTETYPE']; ?></td>
<?php } ?>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
You were missing a closing </td> tag on the first table cell and you need to
use braces for an if statement eg
if($variable == $value){
}elseif($variable == $something_else) {
}
--
Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709258#M194066
Jan 17, 2007
Jan 17, 2007
Copy link to clipboard
Copied
RichardODreamweaver wrote:
> <?php if ($row_Recordset1['NOTETYPE'] ="NOTE")?><td
<?php if ($row_Recordset1['NOTETYPE'] == "NOTE")?><td
Two equals signs, not one.
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
> <?php if ($row_Recordset1['NOTETYPE'] ="NOTE")?><td
<?php if ($row_Recordset1['NOTETYPE'] == "NOTE")?><td
Two equals signs, not one.
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
RichardODreamweaver
AUTHOR
Engaged
,
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709259#M194067
Jan 18, 2007
Jan 18, 2007
Copy link to clipboard
Copied
Thanks Gareth/ David - can't work out the "==" syntax but it
works!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709260#M194068
Jan 18, 2007
Jan 18, 2007
Copy link to clipboard
Copied
Basically, if you want to set something to a value, use 1 =
sign eg
$a = 10
Will set the variable $a to hold the value 10
If you want to check whether the value in a variable is equal to another
value, use 2 = signs eg
if($a == 10){
echo $a . " is equal to 10";
}
Its a common mistake for beginners to use
if($a = 10){
}
This actual sets the value of $a to 10, rather than check the value is equal
to 10, and the condition always runs.
--
Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
$a = 10
Will set the variable $a to hold the value 10
If you want to check whether the value in a variable is equal to another
value, use 2 = signs eg
if($a == 10){
echo $a . " is equal to 10";
}
Its a common mistake for beginners to use
if($a = 10){
}
This actual sets the value of $a to 10, rather than check the value is equal
to 10, and the condition always runs.
--
Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
RichardODreamweaver
AUTHOR
Engaged
,
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709262#M194070
Jan 18, 2007
Jan 18, 2007
Copy link to clipboard
Copied
quote:
Originally posted by: Newsgroup User
This actual sets the value of $a to 10, rather than check the value is equal
to 10, and the condition always runs.
Thanks Gareth
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
RichardODreamweaver
AUTHOR
Engaged
,
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709261#M194069
Jan 18, 2007
Jan 18, 2007
Copy link to clipboard
Copied
Can this code block also be used for dynamic table rows
instead of just layout cells?
Eg:
<tr>
<td>TYPE</td>
<td>OTHER</td>
</tr>
<?php do { ?>
<?php if ($row_recordset['NOTETYPE'] =="Action") { ?>
<tr>
<td bgcolor="#CCCCCC"><?php echo $row_recordset['TYPE']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } elseif ($row_recordset['NOTETYPE'] =="Note") { ?>
<tr>
<td bgcolor="#00FFCC"><?php echo $row_recordset['TYPE']; ?></td>
<td bgcolor="#00FFCC"><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } else { ?>
<tr>
<td><?php echo $row_recordset['TYPE']; ?></td>
<td><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } ?>
This is a much simplified version of a multiple column table I have but mine does not seem to work and seems to jump to the else statement.
Eg:
<tr>
<td>TYPE</td>
<td>OTHER</td>
</tr>
<?php do { ?>
<?php if ($row_recordset['NOTETYPE'] =="Action") { ?>
<tr>
<td bgcolor="#CCCCCC"><?php echo $row_recordset['TYPE']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } elseif ($row_recordset['NOTETYPE'] =="Note") { ?>
<tr>
<td bgcolor="#00FFCC"><?php echo $row_recordset['TYPE']; ?></td>
<td bgcolor="#00FFCC"><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } else { ?>
<tr>
<td><?php echo $row_recordset['TYPE']; ?></td>
<td><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } ?>
This is a much simplified version of a multiple column table I have but mine does not seem to work and seems to jump to the else statement.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709263#M194071
Jan 18, 2007
Jan 18, 2007
Copy link to clipboard
Copied
RichardODreamweaver wrote:
> Can this code block also be used for dynamic table rows instead of just layout
> cells?
Yes, although your code isn't very efficient. This is much simpler:
<?php do { ?>
<?php
$bgcolor = '';
if ($row_recordset['NOTETYPE'] == "Action") {
$bgcolor = ' bgcolor="#CCCCCC"';
}
elseif ($row_recordset['NOTETYPE'] == "Note") {
$bgcolor = ' bgcolor="#00FFCC"';
}
?>
<tr<?php echo $bgcolor; ?>>
<td><?php echo $row_recordset['TYPE']; ?></td>
<td><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } while ($row_recordset = mysql_fetch_assoc($recordsetName)); ?>
> does not seem to work and seems to jump to the else statement.
PHP is case-sensitive. The values must be "Action" or "Note", not
"action" or "note".
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
> Can this code block also be used for dynamic table rows instead of just layout
> cells?
Yes, although your code isn't very efficient. This is much simpler:
<?php do { ?>
<?php
$bgcolor = '';
if ($row_recordset['NOTETYPE'] == "Action") {
$bgcolor = ' bgcolor="#CCCCCC"';
}
elseif ($row_recordset['NOTETYPE'] == "Note") {
$bgcolor = ' bgcolor="#00FFCC"';
}
?>
<tr<?php echo $bgcolor; ?>>
<td><?php echo $row_recordset['TYPE']; ?></td>
<td><?php echo $row_recordset['OTHER']; ?></td>
</tr>
<?php } while ($row_recordset = mysql_fetch_assoc($recordsetName)); ?>
> does not seem to work and seems to jump to the else statement.
PHP is case-sensitive. The values must be "Action" or "Note", not
"action" or "note".
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
RichardODreamweaver
AUTHOR
Engaged
,
LATEST
/t5/dreamweaver-discussions/php-if-else-help-please/m-p/709264#M194072
Jan 18, 2007
Jan 18, 2007
Copy link to clipboard
Copied
Ooops - yes it does seem to work - after erasing the "user
errors", it works a treat!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

