By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

if else trouble

P: n/a
JD
I have the below code that displays a small thumbnail if a user is saluted,
if they aren't saluted it checks to see if they might have a profile
picture, this all works with the exception that is no profile picture exist
it still trys to display a broken image, Im sure it's a simple mistake any
help please?

<?php
if ($commentUser[0]['saluted']=="Yes") {
?>
<img src="../salute/<?php echo $commentUser[0]['login'];
?>/thumbs/random.php" border=0 width="50">
<?php } else { ?>
<?php if
( !is_dir('./profilepic/' . $commentUser[0]['login']) ) {
?>
<img src="../profilepic/<?php echo $commentUser[0]['login'];
?>/thumbs/random.php" border=0 width="50">
<?php } else { ?>
this part doesn't work
<?php
}
} ?>
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hey.. Hi

Looks like you messed up the code, You can keep it loads neater. The
code is small and still it gives problems. :-)

Dont you thinks its better if you can write code like:
if($commentUser[0]['saluted']=="Yes"){
echo '********ALL THAT YOU NEED ***';
}
else
{
echo ' **ALL THE OTHER STUFF';
}

Jul 17 '05 #2

P: n/a
"JD" <ne**@aznfetish.com> wrote:
I have the below code that displays a small thumbnail if a user is saluted,
if they aren't saluted it checks to see if they might have a profile
picture, this all works with the exception that is no profile picture exist
it still trys to display a broken image, Im sure it's a simple mistake any
help please?

<?php
if ($commentUser[0]['saluted']=="Yes") {
?>
<img src="../salute/<?php echo $commentUser[0]['login'];
?>/thumbs/random.php" border=0 width="50">
<?php } else { ?>
<?php if
( !is_dir('./profilepic/' . $commentUser[0]['login']) ) {
You don't want the "!" in there. You're saying if they do NOT have a
profile directory, then display the profile picture, which is guaranteed
not to be found.
?>
<img src="../profilepic/<?php echo $commentUser[0]['login'];
?>/thumbs/random.php" border=0 width="50">
<?php } else { ?>
this part doesn't work
<?php
}
} ?>


--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #3

P: n/a
JD wrote:
I have the below code that displays a small thumbnail if a user is
saluted, if they aren't saluted it checks to see if they might have a
profile picture, this all works with the exception that is no profile
picture exist it still trys to display a broken image, Im sure it's a
simple mistake any help please?

<?php
if ($commentUser[0]['saluted']=="Yes") {

<img src="../salute/<?php echo $commentUser[0]['login'];
/thumbs/random.php" border=0 width="50">

<?php } else { ?>
<?php if
( !is_dir('./profilepic/' . $commentUser[0]['login']) ) {

<img src="../profilepic/<?php echo $commentUser[0]['login'];
/thumbs/random.php" border=0 width="50">

<?php } else { ?>
this part doesn't work
<?php
}
} ?>


Are you aware of print & echo? It's a lot easier than dropping in & out of
PHP to output your HTML - and I'll bet your code would be easier to read.

It's difficult to see what you're trying to do the way it's written.
Anyways, the same thing, a bit cleaned up:

<?php
if ($commentUser[0]['saluted']=="Yes") {
print "<img src='..salute" . $commentUser[0]['login'] .
"/thumbs/random.php' border=0 width=50>\n";
} else {
if ( !is_dir('.profilepic' . $commentUser[0]['login']) ) {
print "<img src='..profilepic". $commentUser[0]['login'] .
"/thumbs/random.php' border=0 width=50>\n";
} else {
print "<p>this part doesn't work</p>\n";
}
}
?>

let's follow the logic:
1 - you're checking if "saluted" is set, and if so, you display a "saluted"
picture.
2 - if "saluted" is NOT set, then you check if for a "profilepic" directory
based on 'login'.
a - if that "profilepic" directory does not exist, you try to display an
image from "profilepic" one directory up from the current
b - if that "profilepic" directory DOES exist, you want to do something
(that isn't happening)

Is that about what you want to have happen?

What, exactly, IS happening, then? Have you tried just putting in a message
(like in the code I supplied above), to see if it's even getting to that
test?

I suspect that at least some of the problems will go away if you clean up
the code a bit.

--
Tony Garcia
Web Right! Development
Riverside, CA
www.WebRightDevelopment.com
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.