/    Sign up×
Community /Pin to ProfileBookmark

If (strlen) problem

Hi all,

Can anyone show me where I am going wrong here.

[code=php]
<?php
if (strlen($row_accomm[‘pic’]) > 0 {
echo $row_accomm[‘pic’];
} else {
echo “awaiting photo”;
}
?>
[/code]

All I am trying to do is test the field ‘pic’ for a string, if there is one show the pic underlying the string.

If field is empty show the message.

Can anyone help please.

Kind regards

Dereck

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Stephen_PhilbinAug 23.2005 — [code=php]
<?php
if (strlen($row_accomm['pic']) > 0 ) {
echo $row_accomm['pic'];
} else {
echo "awaiting photo";
}
?>
[/code]


Does it?

You seemed to be missing the closing parenthesis for the "if" after the zero.
Copy linkTweet thisAlerts:
@dcjonesauthorAug 23.2005 — Hi and thanks for your reply.

I now have it working thanks to you:

[code=php]
<?php
if (strlen ($row_accomm['pic']) == 0)
{
echo "Awaiting picture";
}
else
{
?>
<img src="<?php echo $row_accomm['pic']; ?>">
<?php
}
?>
[/code]


Is there a tidy way to write this short code?

Thanks for your help

Keep safe and well

Dereck
Copy linkTweet thisAlerts:
@Daniel_TAug 23.2005 — I'd write it like this...
[code=php]<?php
echo (strlen($row_accomm['pic']) == 0) ?
"Awaiting picture" :
"<img src="" . $row_accomm['pic'] . "">";
?>[/code]
Copy linkTweet thisAlerts:
@NogDogAug 23.2005 — Even a few less characters... ?
[code=php]
<?php
echo (empty($row_accomm['pic'])) ?
"Awaiting picture" :
"<img src="" . $row_accomm['pic'] . "">";
?>
[/code]
Copy linkTweet thisAlerts:
@dcjonesauthorAug 23.2005 — Hi and thanks for your reply.

I now have it working thanks to you:

[code=php]
<?php
if (strlen ($row_accomm['pic']) == 0)
{
echo "Awaiting picture";
}
else
{
?>
<img src="<?php echo $row_accomm['pic']; ?>">
<?php
}
?>
[/code]


Is there a tidy way to write this short code?

Thanks for your help

Keep safe and well

Dereck
Copy linkTweet thisAlerts:
@MauAug 24.2005 — As mentioned above:

[code=php]
print (empty($row_accomm['pic']) ? 'Awaiting Picture!' : '<img src="'.$row_accomm['pic'].'" />');
[/code]
×

Success!

Help @dcjones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...