dynamic php\html dropdown listing from postgresql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sshade25
    New Member
    • Nov 2009
    • 10

    dynamic php\html dropdown listing from postgresql

    Please I have this problem on my script, It is just pulling the data from the postgresql database but does not place it in the dropdown field created for it on the html form.
    What can possibly be wrong with this script? I have three different forms on this script and just trying to get one to run perfectly

    Code:
    <html>
    <head><title>UG Pipeline Fiedl Data Capture</title>
    </head>
    <body>
    <--HTML Code to create the data entry form-->
    <p>
    </form></P>
      <form action="<?php echo $PHP_SELF; ?>" method="post">
      <table width="600" cellpadding= "10" cellspacing="1" border="2">
     <tr align="center" valign="top">
     <td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
     <h3>Input Field Tally Information</h3>
       Select Pipe No:<select pipeno ="" pipeno ="" >  <option value=""> --- Select --- </option></select>  Select Wall Thickness:<select wellthickness ="" wallthickness ="" >  <option value=""> --- Select --- </option></select>  
        <br><br>
     Input Joint No: <input type="text" name="jointno"> Input measured Length: <input type="text" name="measuredlength"><br><br>
     Input Serial No: <input type="text" name="serialno"><br><br> 
     <input type="Submit" name="submit" value="Submit"> 
      
    <?php
    //Php Code to connect to postgresqldatabase
    
     $PGHOST = "localhost:25376";
     $PGDATABASE = "Pipeline";
     $PGUSER = "postgres";
     $PGPASSWORD = "Casa2009";
     $PGPORT = 5432;
     $db_handle = pg_connect("dbname=$PGDATABASE user=$PGUSER
     password=$PGPASSWORD");
     if ($db_handle) {
     echo 'Connection attempt succeeded.';
     } else {
     echo 'Connection attempt failed.';
     }
    // Code to pull data from the database and load onto the form
    echo "<br />\n";
    $query = 'select * from fieldtally order by pipeno asc '; 
    $result = pg_query($db_handle,$query); 
    while ($row = pg_fetch_row($result))
    {
    //print ("<option> $row[0]</option>");
    } 
    ?>
    </form></P>
    <--Creating a secod form-->
    <form action="fieldbend.php" method="post">
     <table width="600" cellpadding="10" cellspacing="1" border="2">
     <tr align="center" valign="top">
     <td align="center" colspan="1" rowspan="1" bgcolor="#ff9d9d">
      <h3>Input Field Bend Information</h3>
      Select Pipe No:<select pipeno ="" pipeno ="" >  <option value=""> --- Select --- </option></select>  Select Wall Thickness:<select wellthickness ="" wallthickness ="" >  <option value=""> --- Select --- </option></select>  
        <br><br>
       Input Measured Distance: <input type="text" name="measureddistance">  Input Bend Angle: <input type="text" name="benddegree"><br><br>
       Input Bend Type: <input type="text" name="bendtype"><br><br>
     <input type="Submit" name="submit" value="Submit">
     
    </form></P>
    
    <form action="apptally.php" method="post">
     <table width="600" cellpadding="10" cellspacing="0" border="2">
     <tr align="center" valign="top">
     <td align="center" colspan="1" rowspan="1" bgcolor="#66CC66">
     <h3>Input App. Tally Information</h3>
       Input Type: <input type="text" name="type">   Input Serial No: <input type="text" name="serialno"><br><br>
       Input Reference ID: <input type="text" name="referenceid"><br><br>
     <input type="Submit" name="submit" value="Submit">
    </form></P>
    
    
    </form>
    </body>
    </html>
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You're not outputting anything in your loop. And even if you were, you're not outputting it between select elements.

    Comment

    • sshade25
      New Member
      • Nov 2009
      • 10

      #3
      It appears you're right but could you tell me how to do it right? because that is what i really wish to achieve, currently the data pulled from the database is just displaying on the form but not within the select tab.
      The script is meant to output or display information from the database via the two dropdown tabs while the rest of the field are to be entered by the user.
      So I will appreciate if you could give me ideas on how it can be achieved.

      thanks

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You just need to make the two changes I mentioned. It would look a little something like this:
        Code:
        <select>
        <?
        // the rest of your code
        while (your loop condition) {
           echo "<option>$somevalue</option>";
        }
        // the rest of your code
        ?>
        </select>
        First change, put it between select elements, lines 1 and 9 in my code. Second change, output the value, line 5 in my code.

        Comment

        Working...