php "if" condition not working

Hi

$area[0] is either  TITLE or LOGO or TEXT

i want $size to be "10" if $area[0] = TEXT otherwise "50"

but it isn't working. what am i doing wrong?

Thanks!
<?
foreach ($editareas as $area) {$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 

if ($area[0] == "TITLE") {$size = '10';} else {$size = '50';} 
?>
<h3><?=$area[0]?></h3>

Open in new window

peps03Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rik-LeggerCommented:
It seems to simple,
but shouldn't it be the following?

if ($area[0] == "TEXT")
0
Greg AlexanderLead DeveloperCommented:
Not sure if it was a copy paste error, but you were missing a bracket:
<?
foreach ($editareas as $area) {
	$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 

	if ($area[0] == "TITLE") {
		$size = '10';
	} else {
		$size = '50';
	}
}
?>

Open in new window

0
peps03Author Commented:
Thanks for the reactions.

@ Rik-Legger: I made a typo, i meant TITLE

@galexander07: Missing bracket was copy past error.

Excuse me for my carelessness.

now its correct. but it doesn't work correct.
its supposed to set the width of a text area, the first text area (which is TITLE) outputted doesn't get a value (10)..
<? 
foreach ($editareas as $area) 
{
$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
if ($area[0] == "TITLE") {$size = '10';} else {$size = '50';} 
}
?>

Open in new window

0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

peps03Author Commented:
i also added the 2 other lines of code in the foreach condition, maybe they explain more..
this is now how i (would like to) use the code.

<? 
foreach ($editareas as $area) 
{
$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
if ($area[0] == "TITLE") {$size = '10';} else {$size = '50';} 

<h3><?=$area[0]?></h3>
<textarea name="areas[]" rows="<?= max ($numlines, $size) ?>" cols="<?=$areawidth?>" class="tinymce"><?=$area[1]?></textarea>

}
?>

Open in new window

0
Ray PaseurCommented:
"it isn't working" is not one of the error messages I recognize.  It helps if you can describe what is wrong.  Parse error?  No output?  Loop, etc.

Also, you may find it easier to write understandable code if you eliminate compound statements like this (coding standards exist for a reason):
foreach ($editareas as $area) {$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n");

Could you please show us the values of the variables that you are using in the code at ID:35358174?  This appears to be a data-dependent problem and so the contents of these data fields matter.  Thanks, ~Ray
0
liveaspankajCommented:
Seems u mixed up html and php a bit: check this
 
<? 
foreach ($editareas as $area) 
{
$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
if ($area[0] == "TITLE") {$size = '10';} else {$size = '50';} 
?>
<h3><? echo $area[0]; ?></h3>
<textarea name="areas[]" rows="<?= max ($numlines, $size) ?>" cols="<?=$areawidth?>" class="tinymce"><?=$area[1]?></textarea>
<?
}
?>

Open in new window

0
hmarcbowerCommented:
liveaspankaj found the problem.

There's no reason you can't continue using the <?=$area[0]?> though (as long as you don't want portability of your files to different servers).
0
liveaspankajCommented:
yes true that was not essential. its just i have the habit of using the other format that works everywhere.

there actual problem was the other one.
0
peps03Author Commented:
Many thanks for the reactions, i solved the issue this way:

<?
if ($area[0] == 'TITLE') {$size = '5';} 
if ($area[0] == 'LOGO') {$size = '30';} 
if ($area[0] == 'TEXT') {$size = '40';} 
?>

Open in new window


Should i delete this question?
0
liveaspankajCommented:
the problem was somewhere else :) see my posts above
0
peps03Author Commented:
what did you mention that was wrong?
0
liveaspankajCommented:
Please compare these: line (6 and 9)

Your earlier code:
 
<? 
foreach ($editareas as $area) 
{
$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
if ($area[0] == "TITLE") {$size = '10';} else {$size = '50';} 

<h3><?=$area[0]?></h3>
<textarea name="areas[]" rows="<?= max ($numlines, $size) ?>" cols="<?=$areawidth?>" class="tinymce"><?=$area[1]?></textarea>

}
?>

Open in new window


Corrected Code:
 
<? 
foreach ($editareas as $area) 
{
$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
if ($area[0] == "TITLE") {$size = '10';} else {$size = '50';} 

<h3><?=$area[0]?></h3>
<textarea name="areas[]" rows="<?= max ($numlines, $size) ?>" cols="<?=$areawidth?>" class="tinymce"><?=$area[1]?></textarea>

}
?>

Open in new window

<? 
foreach ($editareas as $area) 
{
$numlines = $htmleditor ? $size : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
if ($area[0] == "TITLE") {$size = '10';} else {$size = '50';} 
?>
<h3><?=$area[0] ?></h3>
<textarea name="areas[]" rows="<?= max ($numlines, $size) ?>" cols="<?=$areawidth?>" class="tinymce"><?=$area[1]?></textarea>
<?
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
liveaspankajCommented:
sorry i double embedded the second code
0
peps03Author Commented:
oke, you're right!

Thanks
0
liveaspankajCommented:
thanks for accepting the answer :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.