Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Select Table from a dropdown to pass onto another php page

    hi,

    At current, this is my php for one of my php pages, it gets all the values from a certain value
    PHP Code:
    <?php

    $host
    =""// Host name
    $username=""// Mysql username
    $password=""// Mysql password
    $db_name=""// Database name
    $tbl_name="GENERIC_TRACKING_MATRIX"// Table name

    // Connect to server and select database.
    mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // Retrieve data from database
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);

    // Start looping rows in mysql database.
    while($rows=mysql_fetch_array($result)){
    ?>
    <table><? echo $rows['Spec_Hand']; ?><? echo $rows['more like this']; ?></table>
    <?
    // close while loop
    }

    // close connection
    mysql_close();
    ?>
    What i need help is that, i have 2 more tables with different values in it. In the above code, i mentioned 1 of my table as GENERIC_TRACKING_MATRIX, and i have 2 more like GENERIC_TRACKING_NEW and GENERIC_TRACKING_TEST.

    before i access this page, i would like to have a dropdown showing all 3 tables and based on the selection, the above tbl_name will be replaced and the page is shown.

    thank you for your help in advance.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Sounds like javascript if you want it to instantly change it without going to another page.

    Of course you should be able to point the table name to a select box, so on the page, once you select it, it reloads the page and updates it.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Yes, thats the method i like to use.
    but code wise, i need help,

    can you give me some sample code? thank you

  • #4
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Finally Got it !

    i used $tbl_name=$_REQUEST['flight']; for selecting what table ?

    then, in the main page, i used the below
    PHP Code:
                <form method="POST" action="middle1.php">

                    <
    p><select size="1" onchange="this.form.submit();" name="flight">
                    <
    option>GENERIC_TRACKING_MATRIX</option>
                    <
    option>ULF61_Tracking_Matrix</option>
                    <
    option>36P1_Tracking_Matrix</option>
                    </
    select></p>
                </
    form


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •