graham23s Posted May 9, 2007 Share Posted May 9, 2007 Hi Guys, i have a script here that echoes out a users photo (if they have uploaded one) if not it's just a generic one, what i was wanting to do is display a generic male one if they are male and a female pic if they are female, the code just now is: <?php // Start retrieving user profile from database////////////////////////////////////// $qProfile = "SELECT * FROM membership WHERE username='$member'"; $rsProfile = mysql_query($qProfile) or die(mysql_error()); $row = mysql_fetch_array($rsProfile); // get the resultset into an array///////////// extract($row); // The row items in variables...///////////////////////////////////////////////////// $id = $row['id']; $photo1 = $row['photo1']; $gender = $row['gender']; ?> <p>Upload Main Profile Photo<p> <table width="600" cellspacing="2" cellpadding="2"> <form action="upload_photo_done.php" method="POST" enctype="multipart/form-data"> <tr> <td bgcolor="#E2E2E2">Upload Location:</td><td bgcolor="#E2E2E2" align="left"><input type="file" name="image1" size="40"></></td> <tr> <td bgcolor="#E2E2E2">Current Uploaded Photo:</td><td bgcolor="#E2E2E2"> <?php if($photo1 == 0) { echo "<img src='uploads/no_pic_male.jpg' />"; } else { echo "<img src='uploads/$photo1' border='0' />"; } ?> i was thinking an elseif statement is that possible? cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/50618-displaying-gender-photo/ Share on other sites More sharing options...
only one Posted May 9, 2007 Share Posted May 9, 2007 yes an else if is possilbe if(something==theotherthing){ do something }else if(something==somethingelse){ do something else }else{ do the other ting... } Quote Link to comment https://forums.phpfreaks.com/topic/50618-displaying-gender-photo/#findComment-248812 Share on other sites More sharing options...
nikkieijpen Posted May 9, 2007 Share Posted May 9, 2007 If they didn't upload a photo the the value stored in the database field 'photo1' really is 0 or is it empty? if it's empty: <?php if(empty($photo1)) { switch ($gender) { case "male": echo "<img src='uploads/no_pic_male.jpg' />"; break; case "female": echo "<img src='uploads/no_pic_female.jpg' />"; break; default: echo "<img src='uploads/no_pic.jpg' />"; break; } else { echo "<img src='uploads/$photo1' border='0' />"; } ?> If it's 0 just leave the if statement as you already had it. Quote Link to comment https://forums.phpfreaks.com/topic/50618-displaying-gender-photo/#findComment-248815 Share on other sites More sharing options...
btherl Posted May 9, 2007 Share Posted May 9, 2007 As an aside, there is no need to extract($row) if you are going to explicitly set $id, $photo1 and $gender below. They both perform the same action (though the extract will set all variables, not just the ones you want). Quote Link to comment https://forums.phpfreaks.com/topic/50618-displaying-gender-photo/#findComment-248817 Share on other sites More sharing options...
graham23s Posted May 9, 2007 Author Share Posted May 9, 2007 Hi Guys, Thanks for the help the $photo1 field was indeed empty. i have implemented this code by Nikki <?php if(empty($photo1)) { switch ($gender) { case "Male": echo "<img src='images/no_pic_male.jpg' />"; break; case "Female": echo "<img src='images/no_pic_female.jpg' />"; break; } } else { echo "<img src='uploads/$photo1' border='0' />"; } ?> this does the job it echoes out a female or a male picture depending on signup, only thing is, when i upload a photo in the control panel, it doesn't store the name in mysql (even though it says uploaded succesfully) but if i revert to my initial basic code: <?php if($photo1 == 0) { echo "<img src='uploads/no_pic_male.jpg' />"; } else { echo "<img src='uploads/$photo1' border='0' />"; } ?> it seems to work as before, storing the name in mysql any ideas on why it didn't do this with the revised code? thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/50618-displaying-gender-photo/#findComment-248829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.