选择时的mysql下拉列表

http://img3.mukewang.com/644b69e70001300306520100.jpg

我有一个具有这种结构的表,并尝试使用下拉列表从列表中选择一种语言,然后显示相应 language_id 的内容。我正在使用 mysql 和 php 5.4


我的代码如下,卡在循环中,不知道如何得到它


$sql=mysql_query("SELECT lang_id, lang_desc FROM languages ");


                                if(mysql_num_rows($sql))

                                {

                                    $select= '<select lang_desc="select">';


                                    while($rows=mysql_fetch_array($sql))

                                    {

                                        $select.='<option value="'.$rows['lang_id'].'">'.$rows['lang_desc'].'</option>';

                                    }

}

                                    $select.='</select>';

                                    echo $select ;  


                                    $result = mysql_query("SELECT * FROM contents LEFT JOIN languages ON contents.lang_id = languages.lang_id  WHERE contents.page_name = 'index' AND contents.lang_id =  '$select'");

                                    while ($row = mysql_fetch_array($result))

{


                                     }

请帮忙


慕运维8079593
浏览 93回答 1
1回答

摇曳的蔷薇

我认为这需要至少 2 个 PHP 页面,第一个用于显示数据,第二个用于创建数据,听说我没有创建数据库连接,请在第一个添加它我使用 jquery 从第二个 PHP show.php获取数据<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script><select id="lang" onchange="setlang(this.value)"><?PHP&nbsp;$sql=mysql_query("SELECT lang_id, lang_desc FROM languages");while($rows=mysql_fetch_array($sqL,MYSQL_ASSOC)){&nbsp; &nbsp; echo '<option value="'.$rows['lang_id'].'">'.$rows['lang_desc'].'</option>'}?></select><div id='dis'></div><script type="text/javascript">&nbsp; &nbsp; $( document ).ready(function() {&nbsp; &nbsp; &nbsp; setlang($('#lang').val());&nbsp; &nbsp; });&nbsp; &nbsp; function setlang(val) {&nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: "data.php",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "POST",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data:{val:val},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function(result){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#dis").html(result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }</script>数据.php<?php$result = mysql_query("SELECT * FROM contents LEFT JOIN languages ON contents.lang_id = languages.lang_id&nbsp; WHERE contents.page_name = 'index' AND contents.lang_id =&nbsp; '".$_POST['val']."'");$data="";while ($row = mysql_fetch_array($result))&nbsp; &nbsp; $data.="your row data for dis";&nbsp; &nbsp; //}echo $data;?>
打开App,查看更多内容
随时随地看视频慕课网APP