Jump to content

Archived

This topic is now archived and is closed to further replies.

libinaz

show something if...

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]

Share this post


Link to post
Share on other sites
if $row[0]=='YES'{
    //show your stuff here
    }
else
    {
    //show some other stuff
    }

Share this post


Link to post
Share on other sites
Also you can use it like

if(condition == "something") { ?>
html code here
<? }
else { ?>
more html code
<? }
?>

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.