我需要回显一个下拉选项,它是从另一个页面上的mysql填充的

I have a three drop downs, 2 of which are populated from Mysql, so depending on what is selected in the first, define's what populates in the second, and then third. however. i need to take the users 3 selections, and carry them onto the next page and echo them, and then the same for the third page, i need to take the first pages answers, and the second, and echo them on the third page. and so on. this is my code so far:

<?php
``if (@$_REQUEST['ajax']) {
// connect to local database 'test' on localhost
$link = mysql_connect('localhost', 'user', 'pass');
if ($link == false)
    trigger_error('Connect failed - ' . mysql_error(), E_USER_ERROR);

$connected = mysql_select_db('test', $link);

if ($connected) {
    $results = mysql_query('select * from test.select_chain where category="' . strtolower(mysql_real_escape_string(strip_tags($_REQUEST['category']))) . '"');

    $json = array();

    while (is_resource($results) && $row = mysql_fetch_object($results)) {
        //$json[] = '{"id" : "' . $row->id . '", "label" : "' . $row->label . '"}';
        $json[] = '"' . $row->label . '"';
    }

    echo '[' . implode(',', $json) . ']';
    die(); // filthy exit, but does fine for our example.
} else {
    user_error("Failed to select the database");
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Select Chain</title>
<style type="text/css" media="screen">
<!--
  BODY { margin: 10px; padding: 0; font: 1em "Trebuchet MS", verdana, arial, sans-serif; }
  BODY { font-size: 100%; }
  H1 { margin-bottom: 2px; font-family: Garamond, "Times New Roman", Times, Serif;}
  DIV.selHolder { float: left; border: 3px solid #ccc; margin: 10px; padding: 5px;}
  TEXTAREA { width: 80%;}
  FIELDSET { border: 1px solid #ccc; padding: 1em; margin: 0; }
  LEGEND { color: #ccc; font-size: 120%; }
  INPUT, TEXTAREA { font-family: Arial, verdana; font-size: 125%; padding: 7px; border: 1px solid #999; }
  LABEL { display: block; margin-top: 10px; } 
  IMG { margin: 5px; }
  SELECT { margin: 10px; width: 200px; }
-->
</style>

<script src="jquery.js" type="text/javascript"></script>
<script src="select-chain.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
<!--
$(function () {
    var cat = $('#categorySelect');
    var el = $('#elementSelect');
    var attr = $('#attributeSelect');

    el.selectChain({
        target: attr,
        url: 'index.php',
        data: { ajax: true, anotherval: "anotherAction" }            
    });        

    // note that we're assigning in reverse order
    // to allow the chaining change trigger to work
    cat.selectChain({
        target: el,
        url: 'index.php',
        data: { ajax: true }
    }).trigger('change');

});
//-->
   </script>
  </head>
    <center><img src="tgd.png" alt="The Global Dollar" href="index.php"></center>
   <body id="page">
    <div id="doc">
    <center><h1>Country</h1></center>
    <div class="selHolder">
        <h2>Continent</h2>
        <select id="categorySelect" name="category" size="5">
          <option>Africa</option>
      <option>America</option>
  <option>Antarctica</option>
  <option>Asia</option>
  <option>Australia</option>
  <option>Europe</option>
        </select>
    </div>
    <div class="selHolder">
        <h2>Country</h2>
        <select id="elementSelect" name="category" size="5">
            <option>[none selected]</option>
        </select>
    </div>
    <div class="selHolder">
        <h2>City</h2>
        <select id="attributeSelect" name="category" size="5">
            <option>[none selected]</option>
        </select>
    </div>
    </div>
   <a href="../secondpage">Next Page </a>
  </body>
</html>

Anyone know how i can do this? sorry if i have been unclear, its hard to describe. thanks in advance

Here are some ways a web client can pass information to the next page loaded:

  • Put the information in the URL's query string (basically what happens when you submit a form via GET). The next page can parse the query string.
  • Send the information to the server as POST data when the user goes to the next page. The server can write the information into the next page as it's delivered.
  • You can build upon the prior idea by storing the information with PHP sessions. That would let the server remember the user's selections for a period of time even if the user leaves the page and comes back.
  • You could store the information in cookies. Cookies can be set and read entirely with JavaScript if you want.
  • HTML5 local storage is probably overkill, but if you're going to end up building something complex....

You are talking about Dynamic Dropdown functionality here. And going by fetching the options from MySQL, I found a source for you.

May be you can refer this and sort it out.

Dynamic Dropdown Powered by MySQL