SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry creating pull-down menus from database records

    We have created a pull-down menu that lists all of the records in a table. Now we need to create links from each of the records to display all of the details of the record. This is the code that generates the menu.

    PHP Code:
    echo "
     <option value=\"news_display8.php?id="
    .$row['recid']."\">$row[articledate]$row[title]</option>
         "
    ;} 
    We then have a second file that is supposed to display the details of the record. The problem is that it isn't recognizing each value as a link. How do we pass the record id thru the url? Please help.

    These are the fields the display page is getting from the database. The display page is working if we display the records as text links instead of a pull-down menu.

    PHP Code:
    $sql "SELECT recid, title, articledate, content FROM news WHERE recid = '$id'"

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using <option></option> suggests your using a form. So you would make a selection then submit a form and then do form processing. If your just trying to make a list of links then try <a href= ...please.
    Erh

  3. #3
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandibal
    Using <option></option> suggests your using a form. So you would make a selection then submit a form and then do form processing. If your just trying to make a list of links then try <a href= ...please.
    We have a form which submits to a processing form file called news_display9.php:

    PHP Code:
    <form action="news_display9.php?id=[$recid]" method="post"
    We want to pass the recid information to the URL of the page that will display the full details. What are we doing wrong?

  4. #4
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't pass id='$id' through the action value in a form. In order to pass this variable to the next page you will have to create a hidden tage. <input type=hidden name=name value=value> Then once the form in submitted, it will have the variable $_POST[name] (or just $name) and the value wil be 'value'.

  5. #5
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We are frustrated and very new at this. Please have a look and see if you can help! thanks.

    Code from the first file that is displaying the database records in a drop down menu:

    PHP Code:
    <form action="news_display9.php" method="post">
    <?php                    

    //prepare the select statement
    $sql "SELECT * FROM news WHERE category='Announcements' order by articledate DESC";

    //execute the select statment
    $result mysql_query($sql$db);

    //display results in a drop down menu
    echo "
    <table>
    <tr>
    <td><select>
    "
    ;
    //results
    $err mysql_error();
    echo 
    $err;
    while(
    $row mysql_fetch_array($result))
    {
    echo 
    "
    <option value=
    $row[recid]>$row[articledate]$row[title]</option>
         "
    ;}
         
    echo 
    "</select></td></tr></table>";?> 
       </p><input type=hidden name=recid value='$recid'><input type=submit value="Submit">
     </form>
    Code from the processing file that is supposed to display the selected record from the drop down:

    PHP Code:
    <?php                    
    $id 
    $_GET['id'];
    $result mysql_select_db("dbname"$db); 
    if ( 
    $result == false

          echo 
    mysql_error(); 
    } else { 
          
    $sql "SELECT recid, title, articledate, content FROM news WHERE recid = '$id'"
          
    $result mysql_query$sql$db); 
          if ( 
    $result != false 
          { 
                   
    $row mysql_fetch_assoc$result ); 
                   echo 
    "
    <table><tr><td><p>
    $row[articledate]</p> <p><strong>$row[title]</strong></p><br><p>$row[content]</p></td></tr>";

                   echo 
    "</table>"
                 
          } else { 
                echo 
    mysql_error(); 
          } 

    ?>
    we are desparate and ready to give up on this php stuff!!!!!

  6. #6
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:
    PHP Code:
    <form action="news_display9.php" method="post"> 
    <?php 
     
    //prepare the select statement 
    $sql "SELECT * FROM news WHERE category='Announcements' order by articledate DESC"
     
    //execute the select statment 
    $result mysql_query($sql$db) or die(mysql_error()); 
     
    //display results in a drop down menu 
    echo 
    <table> 
    <tr> 
    <td><select name=\"articleID\"> 
    "

    //results 

    while($row mysql_fetch_array($result)) 

    echo 

    <option value=
    $row[recid]>$row[articledate]$row[title]</option>";


    echo 
    "</select></td></tr></table>";?> </p><input type=submit value="Submit"> 
     </form>
    and this:
    PHP Code:
    $id $_POST['articleID']; 
    $result mysql_select_db("dbname"$db) or die(mysql_error());  
      
    $sql "SELECT recid, title, articledate, content FROM news WHERE recid = '$id'";  
        
    $result mysql_query$sql$db) or die(mysql_error());  
              if (
    $row mysql_fetch_assoc$result )){  
               echo 

    <table><tr><td><p>
    $row[articledate]</p> <p><strong>$row[title]</strong></p><br><p>$row[content]</p></td></tr>"
     
                 echo 
    "</table>";  
          }  else {
             print 
    "There were no results returned";
          }
    }  
    ?> 
    Erh

  7. #7
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are AWESOMMMMMEEEE!!!

    thanks a lot, it worked!

  8. #8
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would we modify the code so that instead of displaying a database record it would open a .pdf file when selected?

  9. #9
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess in the page that gets the form data on submission you could try
    PHP Code:
    header("Location: ".$nameOfPDF); 
    to redirect to the pdf file an let the browser handle the rest.
    Erh


Bookmarks

Posting Permissions

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