Jump to content


Photo

if else to display form


  • Please log in to reply
3 replies to this topic

#1 xtiancjs

xtiancjs
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts

Posted 02 April 2006 - 12:51 AM

Hi all, I am trying to write a hopefully simple if else statement that would be something like this psuedo code

if $variable = o display <form>form content</form>
else echo"some message to the user"

not quite sure how I would write that.

xtian

#2 kenrbnsn

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

Posted 02 April 2006 - 01:06 AM

Have you tried anything yet?

Something like this should work:

<?php
if ($variable == 'o') { ?>
<form ...>

</form>
<?php } else echo "some message to the user<br>\n";
?>

Ken

#3 xtiancjs

xtiancjs
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts

Posted 02 April 2006 - 01:13 AM

[!--quoteo(post=360766:date=Apr 1 2006, 08:06 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 1 2006, 08:06 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Have you tried anything yet?

Something like this should work:

<?php
if ($variable == 'o') { ?>
<form ...>

</form>
<?php } else echo "some message to the user<br>\n";
?>

Ken
[/quote]

Thanks for the quick reply, I have attempted a few things , I had enclosed everything in only one <?php ?>, and was having trouble with my form,thanks again ,will try it out
xtian

#4 xtiancjs

xtiancjs
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts

Posted 02 April 2006 - 01:38 AM

[!--quoteo(post=360768:date=Apr 1 2006, 08:13 PM:name=xtiancjs)--][div class=\'quotetop\']QUOTE(xtiancjs @ Apr 1 2006, 08:13 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Thanks for the quick reply, I have attempted a few things , I had enclosed everything in only one <?php ?>, and was having trouble with my form,thanks again ,will try it out
xtian
[/quote]

Hi , just intergrated your suggestion Ken, it worked like a charm, out of general interest here is the final code I used
<td><?php $vipone = $_SERVER['REMOTE_ADDR'];
               $viponeq = mysql_query("SELECT ip FROM voter_ip WHERE ip = '$vipone'");
               if ($viponeq == '0') { ?>
            <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
                <table align="center">
                  <tr valign="baseline">
                    <td nowrap align="right"><select name="broker_rating" onClick="DoSubmission1();">
                        <?php
do {  
?>
                        <option value="<?php echo $row_valueset['value']?>"<?php if (!(strcmp($row_valueset['value'], $row_bprofile['broker_rating']))) {echo "selected=\"selected\"";} ?>><?php echo $row_valueset['value']?></option>
                        <?php
} while ($row_valueset = mysql_fetch_assoc($valueset));
  $rows = mysql_num_rows($valueset);
  if($rows > 0) {
      mysql_data_seek($valueset, 0);
      $row_valueset = mysql_fetch_assoc($valueset);
  }
?>
                      </select></td>
                    <td></td>
                  <tr>
                </table>
                <input type="hidden" name="id" value="<?php echo $row_bprofile['id']; ?>">
                <input type="hidden" name="broker_num_votes" value="<?php echo $row_bprofile['broker_num_votes']; ?>">
                <input type="hidden" name="MM_update" value="form1">
                <input type="hidden" name="id" value="<?php echo $row_bprofile['id']; ?>">
                <input type="hidden" name="ip" value="<?php echo($_SERVER['REMOTE_ADDR']); ?>">
                <input type="hidden" name="page" value="<?php echo($_SERVER['REQUEST_URI']); ?>">
                <input type="hidden" name="MM_insert" value="form1">
              </form><?php } else echo "You have already voted!<br>\n"; ?></td>

thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users