Jump to content


Photo

show something if...


  • Please log in to reply
4 replies to this topic

#1 libinaz

libinaz
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 July 2006 - 11:49 PM

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
<?php $query_contact = "SELECT * FROM students_tbl 
WHERE institutioncontact = 'yes' AND institutionname = '$institutionname'"; 
$institutioncontact = mysql_query($query_contact) or die(mysql_error());?>

here is what I want to show if there is not a 'yes'
                          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>


#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 08 July 2006 - 11:58 PM

if $row[0]=='YES'{
    //show your stuff here
    }
else
    {
    //show some other stuff
    }

#3 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 09 July 2006 - 12:42 AM

Also you can use it like

if(condition == "something") { ?>
html code here
<? }
else { ?>
more html code
<? }
?>
Why doesn't anyone ever say hi, hey, or whad up world?

#4 libinaz

libinaz
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 09 July 2006 - 03:18 PM

if $row[0]=='YES'{
     //show your stuff here
     }
else
    {
     //show some other stuff
     }


can someone help me write this code properly.
<?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>
     }
         ?>


#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 03:39 PM

You have the "echo" in the wrong place:
<?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>';
     }
?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users