libinaz Posted July 8, 2006 Share Posted July 8, 2006 Hi, I have a query that selects 'yes' from a field. If there is no 'yes' then I need to show something...if there is a Yes, then I just need to show who the yes belongs to.here is the query[code] <?php $query_contact = "SELECT * FROM students_tbl WHERE institutioncontact = 'yes' AND institutionname = '$institutionname'"; $institutioncontact = mysql_query($query_contact) or die(mysql_error());?>[/code]here is what I want to show if there is not a 'yes'[code] Member Contact Information: You currently do not have an institution contact, please select.<br> <select name="institutioncontact" class="formbodytext" id="select" tabindex="1"> <option value="" selected>Select One <option value="Yes">Yes, make me the Institution Contact <option value="No">No, we already have an Institute Contact </select>[/code] Link to comment https://forums.phpfreaks.com/topic/14065-show-something-if/ Share on other sites More sharing options...
AV1611 Posted July 8, 2006 Share Posted July 8, 2006 if $row[0]=='YES'{ //show your stuff here }else { //show some other stuff } Link to comment https://forums.phpfreaks.com/topic/14065-show-something-if/#findComment-54983 Share on other sites More sharing options...
corbin Posted July 9, 2006 Share Posted July 9, 2006 Also you can use it like if(condition == "something") { ?>html code here<? }else { ?>more html code <? }?> Link to comment https://forums.phpfreaks.com/topic/14065-show-something-if/#findComment-54987 Share on other sites More sharing options...
libinaz Posted July 9, 2006 Author Share Posted July 9, 2006 [quote author=AV1611 link=topic=99917.msg393783#msg393783 date=1152403088]if $row[0]=='YES'{ //show your stuff here }else { //show some other stuff }[/quote]can someone help me write this code properly. [code]<?php $query_contact = "SELECT * FROM student_tbl WHERE institutioncontact = 'yes' AND institutionname = '$institutionname'"; $institutioncontact = mysql_query($query_contact) or die(mysql_error()); $row = mysql_fetch_assoc($institutioncontact); if ($row['institutioncontact']=='yes'){ Your institution contact is echo $row['institutioncontact']; }else {Your institution currently does not have an institution contact. Please select if you would like to become the contact.<select name="institutioncontact" class="formbodytext" id="select" tabindex="1"> <option value="" selected>Institution Contact <option value="Yes">Yes, make me the institution contact <option value="No">No Contact </select> } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/14065-show-something-if/#findComment-55180 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 You have the "echo" in the wrong place:[code]<?php $query_contact = "SELECT * FROM student_tbl WHERE institutioncontact = 'yes' AND institutionname = '$institutionname'";$institutioncontact = mysql_query($query_contact) or die("Problem with the query: $query_contact<br>" . mysql_error());$row = mysql_fetch_assoc($institutioncontact);if (isset($row['institutioncontact'] && $row['institutioncontact']=='yes'){ echo 'Your institution contact is ' . $row['institutioncontact']; }else { echo 'Your institution currently does not have an institution contact. Please select if you would like to become the contact.'; echo '<select name="institutioncontact" class="formbodytext" id="select" tabindex="1">'; echo '<option value="" selected>Institution Contact</option>'; echo '<option value="Yes">Yes, make me the institution contact</option>'; echo '<option value="No">No</option>'; echo '</select>'; }?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/14065-show-something-if/#findComment-55192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.