Help with dynamic drop down menu

Discussion in 'PHP' started by wpg56, Nov 4, 2009.

  1. #1
    I'm working with PHP and MYSQL. The information is stored in a table called manitobans. The values are ID, firstName, lastname, DOB, Information, image, and alt.

    There is a dynamically created drop down menu (as you add to the mysql database it adds that information automatically to the drop down) on the left side. Select a name from the drop down menu, click the submit button and the information on that person is displayed perfectly on the right hand side.

    The problem I have is that I would like to have some welcome text in the area where the information displays on the right hand side when you enter the site and before clicking on submit. Right now its empty and anyplace I have tried to enter text it is still visible after choosing a person and submitting.







    <!-- START OF CONTENT ON LEFT SIDE OF PAGE

    <?php

    // If submitted, check the value of "select". If its not blank value, get the value and put it into $select

    if(isset($select)&&$select!=""){
    $select=$_GET['select'];
    }

    ?>

    <!-- CREATE THE FORM -->

    <form id="form1" method="get" action="index.php">


    <select name="manitobans">
    <option value="select" selected="selected">Notable Manitobans</option>

    <?php
    // GET ALL THE RECORDS FROM THE TABLE MANITOBANS

    $list=mysql_query("SELECT * FROM manitobans ORDER BY lastName");

    // SHOW RECORDS WITH WHILE LOOP

    while($row_list=mysql_fetch_assoc($list)){

    ?>

    <option value="<?php echo $row_list['ID']; ?>" <?php if($row_list['ID']==$manitobans){ echo "selected =\"selected\""; } ?>><?php echo $row_list['alt'];?>
    </option>

    <!-- END WHILE LOOP-->

    <?php } ?>

    </select>


    <input type="submit" name="Submit" value="Select" />


    </form>


    <!-- END OF LEFT HAND SIDE OF PAGE -->


    <!-- THIS IS DISPLAYED ON THE RIGHT SIDE OF PAGE -->


    <?php

    if (isset($manitobans)&&$manitobans!=""){

    // GET ALL THE RECORDS FROM THE TABLE MANITOBANS

    $result=mysql_query("SELECT * FROM manitobans WHERE ID ='$manitobans'");
    $row=mysql_fetch_assoc($result);
    ?>

    //DISPLAY RESULTS TO PAGE

    <?php echo $row['firstName']; ?>
    <?php echo $row['lastName']; ?>
    <?php echo $row['DOB']; ?>
    <img src="<?php echo $row['Image'];?>" alt ="<?php echo $row['alt'];?>" />

    // GET TXT FILE AND DISPLAY TO PAGE

    <?php $file1=($row['Information']);
    if (file_exists($file1))
    {
    $file = fopen(($row['Information']), "r");
    while (!feof($file))
    {
    $display = nl2br (fgets($file, filesize(($row['Information']))));
    echo $display . "";
    }
    fclose($file);
    }
    else
    {
    echo "no information available for this person";
    }
    ?>


    <!-- END OF IF STATEMENT AND RIGHT SIDE CONTENT -->

    <?php } ?>
     
    wpg56, Nov 4, 2009 IP
  2. smcblogger

    smcblogger Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <input type="hidden" name="test" value="testValue">

    if(isset($_POST['test'])){$test = $_POST['test'];}
    if ($test == "testValue") {
    //do stuff
    }
    else{
    echo "Welcome";
    }
     
    smcblogger, Nov 4, 2009 IP
  3. wpg56

    wpg56 Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for your quick reply.
    However, I am not an expert in PHP and I have tried to place that code into various parts of my code but have not been able to make it work. Where would that statement go.
     
    wpg56, Nov 5, 2009 IP
  4. smcblogger

    smcblogger Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <input type="hidden" name="test" value="testValue"> // This line would go in your form (put above or below the other input line, so when your form is submitted it will POST test with a value of testValue

    // The section below would go on your right side and will show Welcome if test has not been posted. Obviously, where it says do stuff you have to replace with what you want to show or do when the button has been pushed

    if(isset($_POST['test'])){$test = $_POST['test'];}
    if ($test == "testValue") {
    //do stuff
    }
    else{
    echo "Welcome";
    }
     
    smcblogger, Nov 5, 2009 IP
  5. wpg56

    wpg56 Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you for your quick help. That worked great! Just what I was looking for.
     
    wpg56, Nov 5, 2009 IP