drpfu51608120170 2014-08-20 21:12
浏览 19

根据下拉选择显示内容?

Does anyone know how to get the content to render when a user selects a specific month from a dropdown menu? I feel like there's something needed with the form. And I've declared each month, so want to render the content if the month matches the dates in the database. Thoughts? Thanks!

<div id="content">
    <h1>Search by Album, Artist, or Genre</h1>
    <form  method="GET" action=""  > 
            <select>
            <option value="selectmonth">Select a month</option>
            <option value="July 2014" name="July">July 2014</option>
            <option value="August 2014" name="August">August 2014</option>
            <option value="September 2014" name="September">September 2014</option>

</select>
        </form> 
        <br />
    <?php 


$conn = new COM("ADODB.Connection") or die("Cannot start ADO");

$connString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\FinalProject.mdb";

//creates the connection object and define the connection string

$month1 = $_GET ['July'];
$month2 = $_GET ['August'];
$month2 = $_GET ['September'];

//update
$conn->Open($connString);
$selectCommand="SELECT * FROM products WHERE  relasedate LIKE '$released'";

if(isset($_GET['July','August','September'])){

$rs = $conn->Execute($selectCommand);

//execute search when user selects month

if (!$rs->EOF){
    print "<h2>New releases for '<b>$released</b>':</h2>";
} //search results header

if ($rs->EOF){
    print "No results found.<br /><br />";
}else{
    while (!$rs->EOF){ 
        $selectCommand=$rs->Fields("ItemID");
        $artist=$rs->Fields("artist");
        $album=$rs->Fields("album");
        $genre=$rs->Fields("Genre");
        $desc=$rs->Fields("itemdesc");
        $recordl=$rs->Fields("recordlabel");
        $released=$rs->Fields("releasedate");
        $images=$rs->Fields("photos");

        echo "
        <div><img src=$images></div>
        <div><b>Artist</b>: $artist <br />
        <b>Album</b>: $album <br />
        <b>Record Label</b>: $recordl <br />
        <b>Release Date</b>: $released <br />
        <b>Genre</b>: $genre <br />
        <b>Description</b>: $desc <br />
        </div>";

        $rs->movenext();
    } //while loop to render results
} //end if statement for null results


$rs->Close;
} //close connection
?>

    </div>
  • 写回答

1条回答 默认 最新

  • duanpei4455 2014-08-20 21:37
    关注

    Make a div in the page which we will call contentDiv. Secondly, use AJAX to update the div:

    <script>
    function loadContent(selectedVal) {
         var xmlhttp;
         if (window.XMLHttpRequest) {
              // code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
         } else {
              // code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
         xmlhttp.onreadystatechange=function() {
              if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                    document.getElementById("contentDiv").innerHTML=xmlhttp.responseText;
              }
         }
         xmlhttp.open("GET","getInfoFromDatabase.php?selected=" + selectedVal,true);
         xmlhttp.send();
    }
    </script>
    

    You would have to add onchange="loadContent(this.value)" to your select box to get its value.

    You would then have getInfoFromDatabase.php return whatever you need based on the $_GET['selected'] value.

    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教