php – 显示从下拉列表中恢复的数据

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 显示从下拉列表中恢复的数据脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要帮助.我想显示三个数据值,用户将从3个下拉列表中选择这三个数据值.
我创建了三个下拉列表,其中用户将从数据库中为每个选项选择3个不同的选项,然后用户将选择的任何内容必须出现在表中.例如,如果用户为choices_id选择111,为fixture_id选择222,则为名称选择Jesty,它应显示
111 222 Jesty在桌子上.
现在我只有下拉列表从数据库中检索信息,然后显示下降… Wat.我需要一种方法显示用户选择,或 javascript将打印给用户他选择的内容

这是我的3下拉列表

require "config.PHP"; //Database connection
    $resource_selections = MysqL_query("SELECT DISTINCT selection_id From selections ORDER BY selection_id ASC");
    $selections = array();
    while($row = MysqL_fetch_row($resource_selections)){
        $selections[] = $row[0];    
    } 
    $resource_fixtures = MysqL_query("SELECT DISTINCT fixture_id From selections ORDER BY selection_id ASC"); 
    $fixtures = array();
    while($row = MysqL_fetch_row($resource_fixtures)){
        $fixtures[] = $row[0];
    } 
    $resource_names   = MysqL_query("SELECT DISTINCT name FROM selections ORDER BY selection_id ASC");    
    $names = array();
    while($row = MysqL_fetch_row($resource_names)){
        $names[] = $row[0];
    }
    if(count($selections) <= 0 || count($fixtures) <= 0 || count($names) <= 0){
        echo 'No results have been found.';
    } else {

        // Display form
        echo '<form name="form" method="post" action="selection.PHP">';

        //SelectionID dropdown:
        echo "<select name='selection_id' id='selections' >"; 
        foreach($selections as $selection) echo "<option id='$selection'>$selection</option>";
        echo '</select>';

        //FixtureiD dropdown
        echo "<select name='fixture_id' id='fixtures' >"; 
        foreach($fixtures as $fixture) echo "<option id='$fixture'>$fixture</option>";
        echo '</select>';

        //Name dropdown
        echo "<select name='name' id='names' >"; 
        foreach($names as $name) echo "<option id='$name'>$name</option>";
        echo '</select>';

        echo "<input tyPE='submIT' name='submit' value='Submit' />";




        echo '</form>';



    }


    ?>

解决方法

你可以这样试试

<script type="text/javascript">

    function mergeval(val,flag)
    {
      if(flag==1)
      document.getElementById('mvalue1').innerHTML = val ;
      else if(flag==2)
      document.getElementById('mvalue2').innerHTML = val;
      else if(flag==3)
      document.getElementById('mvalue3').innerHTML = val;
    }

    </script>
<?PHP
session_start();
$_SESSION['values']=!empty($_SESSION['values']) ? $_SESSION['values']:array();
if(!empty($_REQUEST['selection_id'])&&!empty($_REQUEST['fixture_id'])&amp;&!empty($_REQUEST['name']))
{
 $_SESSION['values'][] = array('id'=>$_REQUEST['selection_id'],'fid'=>$_REQUEST['fixture_id'],'name'=>$_REQUEST['name']);
}
$dispval ="<table>";

foreach(@$_SESSION['values'] as $key=>$val)
{

$dispval .="<tr><td>".$val['id']."&nbsp;".$val['fid']."&nbsp;".$val['name']."</td></tr>";

}
$dispval .="</table>";
echo $dispval;

?>
    <?PHP
    require "config.PHP"; //Database connection
        $resource_selections = MysqL_query("SELECT DISTINCT selection_id FROM selections ORDER BY selection_id ASC");
        $selections = array();
        while($row = MysqL_fetch_row($resource_selections)){
            $selections[] = $row[0];    
        } 
        $resource_fixtures = MysqL_query("SELECT DISTINCT fixture_id FROM selections ORDER BY selection_id ASC"); 
        $fixtures = array();
        while($row = MysqL_fetch_row($resource_fixtures)){
            $fixtures[] = $row[0];
        } 
        $resource_names   = MysqL_query("SELECT DISTINCT name FROM selections ORDER BY selection_id ASC");    
        $names = array();
        while($row = MysqL_fetch_row($resource_names)){
            $names[] = $row[0];
        }
        if(count($selections) <= 0 || count($fixtures) <= 0 || count($names) <= 0){
            echo 'No results have been found.';
        } else {

            // Display form
            echo '<form name="form" method="post" action="selection.PHP">';

            //SelectionID dropdown:
            echo "<select name='selection_id' id='selections' onchange='javascript:mergeval(this.value,1)'>"; 
            foreach($selections as $selection) echo "<option id='$selection'>$selection</option>";
            echo '</select>';

            //FixtureID dropdown
            echo "<select name='fixture_id' id='fixtures' onchange='javascript:mergeval(this.value,2)' >"; 
            foreach($fixtures as $fixture) echo "<option id='$fixture'>$fixture</option>";
            echo '</select>';

            //Name dropdown
            echo "<select name='name' id='names' onchange='javascript:mergeval(this.value,3)'>"; 
            foreach($names as $name) echo "<option id='$name'>$name</option>";
            echo '</select>';

            echo "<input type='submit' name='submit' value='Submit' />";




            echo '</form>';



        }


        ?>
    <table>
    <tr><td >&nbsp;<span id="mvalue1"></span>&nbsp;<span id="mvalue2"></span>&nbsp;<span id="mvalue3"></span></td></tr>
    </table>

脚本宝典总结

以上是脚本宝典为你收集整理的php – 显示从下拉列表中恢复的数据全部内容,希望文章能够帮你解决php – 显示从下拉列表中恢复的数据所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。