Jump to content

show something if...


libinaz

Recommended Posts

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
Share on other sites

[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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.