Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Location
    KY
    Posts
    2

    Unanswered: Help!! Dropdown to Textarea via MySql

    Hopefully someone here can help me... I am drawing a complete blank and feel like an idiot but here goes....

    I am trying to get a drowdown box populated by field b of table A to OnSelect display field b of table B in a textbox below (note: field a of both is id) underneath

    the text box it would have update to effect changes if necessary (this part if optional - probably better to have it updated on an admin screen.) Anyway im

    stuck...got the javascript/php/mysql to popluate to the dropdown no probably then drew a blank.

    I have tried countless way to effect the proper result. Still having trouble. Below is the latest code tried.

    Thanks for you help.

    PHP Code:
    <html>

    <head>
    <title></title>
    </head>

    <body>
    <table width="100%" align="center" cellspacing="0" cellpadding="0">
    <tr valign="bottom">
    <td width="50%" align="right">
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <form name="testing" method="GET" action="<?=$PHP_SELF?>">
    Filter by
    <select name="testing">
    <?php
    require("hits.php");
    require (
    "db.php");
    $result mysql_query("SELECT * FROM title ORDER BY id");
    $query "SELECT * FROM title ORDER BY id ASC";
    function 
    displayerror($message) {
    printf("<span class=\"formerror\">%s</span>\n"$message);
    }
    if (!(
    $result mysql_query($query))) {
    displayerror(sprintf("Internal ****ed up error %d:%s\n"mysql_errno(), mysql_error()));
    exit();
    // end if
    if($result) {
    while(
    $row=mysql_fetch_array($result)){
    ?>
    <option value="<? echo $row['id']; ?>"><? echo $row['title']." ".$row[''];?></option>
    <?
    // end while
    // end if
    ?>
    </select> <p>&nbsp;
    <textarea name="n" cols="60" rows="10" ><?php echo $row ?></textarea>



    </body>

    </html>
    Last edited by rhs98; 10-21-04 at 05:42. Reason: format the post properly (i.e. php tag)

  2. #2
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    PHP Code:
    <form name="testing" method="GET" action="">
    Filter by
    <select name="testing" onchange="this.form.submit()">
    <?php
    require("hits.php");
    require(
    "db.php");

    $query "SELECT * FROM title ORDER BY id ASC";
    $result mysql_query($query);

    if (!
    $result)
    {
        die(
    mysql_errno() . ': ' mysql_error());
    }
    else
    {
        while(
    $row mysql_fetch_array($result))
        {
        
    ?>
        <option value="<? echo $row['id']; ?>"><? echo $row['title'];?></option>
        <?
        
    }
    }

    //enter the bit to display the textbox
    if(isset($_GET['testing']))
    {
        
    $query sprintf("SELECT * FROM blah WHERE id = %d",$_GET['testing']);
        
    $result mysql_query($query);
        
        if (!
    $result)
        {
            die(
    mysql_errno() . ': ' mysql_error());
        }
        else
        {
            
    //there may be > one row - but I don't know...
            
    if(mysql_num_rows($result)>0)
            {
            
    ?>
            <textarea name="n" cols="60" rows="10" ><?php echo $row['somecolumn']; ?></textarea> 
            <?php
            
    }
            else
            {
                echo 
    "Not found!";
            }
        }
    }
    ?>

    Dude you code was quite messy...


    I've made some assumptions, but this will (should ) do;

    Get a list of stuff, and display it in a select drop down box.

    When the selection is changed, it will resubmit the form - reloading the page.

    The script will then detect the page has been reloaded and display the data from the second query (if found).


    HTH.

Posting Permissions

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