dp518158 2018-05-15 17:29
浏览 72

php文件与mySql数据库使用Javascript html

So I am trying to get create a HTML that uses javascript, PHP, and CSS. I am having issues figuring out how to get the PHP that pulls in my database to post on the website with a click of a button using a javascript function. I have tried to setup jquery and ajax but I just can't seem to get it to work. Everything is connected as it should be. I have googled and googled and tried many things so figured I would post and see if someone can help me out. If I post the PHP file into my HTML it works properly but I have multiple querys that I want associated with a button. If I can just get one button to work I should be good to go. Thank you.

JS

function mad_hosp(str) {
    if(str == 0){ 
        document.getElementById("output").innerHTML = "Error.";
        return;
    } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("output").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET", "madison_narc.php?",  true);
        xmlhttp.send();
    }
}

Here are my buttons in HTML

<div class="navbar">
    <a href="#home">Home</a>
    <a href="#news">News</a>
    <div class="dropdown">
        <button class="dropbtn">Dropdown 
            <i class="fa fa-caret-down"></i>
        </button>
        <div class="dropdown-content">
            <button onclick="main_hosp()"> 
                <a href=("#") class="button">Huntsville Hospital</a>
            </button>
            <button onclick="W&C_hosp()"> 
                <a href=("#") class="button">Womens and Childrens Hospital</a>
            </button>
            <button onclick="mad_hosp()">
                <a href=("#") class="button">Madison Hospital</a>
            </button>
        </div>
    </div> 
</div>


<p>Waiting for the location to be selected... <id="output"></p>

PHP

 <?php
 $sql = "SELECT
 currentinventoryaudit.MedId as MedID,
 (currentinventoryaudit.MedDescription) as MedicationDescription,
 sum(currentinventoryaudit.CurrentCount) as TotalOnHand,
 'MadisonNarcVault' as StationName

 FROM
 currentinventoryaudit

 where
 currentinventoryaudit.StationName like ('%CW101296%') and
 currentinventoryaudit.MedDescription not like ('key%') and
 currentinventoryaudit.MedDescription not like ('%zz-%') and
 currentinventoryaudit.MedDescription not like ('%alp%')

 group by
 2

 order by
 2 asc;";

 $result = mysqli_query($conn,$sql);
 $resultCheck = mysqli_num_rows($result);

 echo "<table>
    <tr>
    <th>MedID</th>
    <th>Medication Description</th>
    <th>Total On Hand</th>
    <th>Station Name</th>
    </tr>";
 if($resultCheck > 0) {
     while ($row = mysqli_fetch_assoc($result)){
        echo"<tr>";
        echo "<td>" . $row['MedID']."</td>";
        echo "<td>" . $row ['MedicationDescription']."</td>";
        echo "<td>" . $row ['TotalOnHand']."</td>";
        echo "<td>" . $row ['StationName']."</td>";
        echo "</tr>";
     }
     echo "</table>";
 }
 ?>
  • 写回答

1条回答 默认 最新

  • duanmu8911 2018-05-15 17:55
    关注

    This doesn't look like valid markup.

    <p>Waiting for the location to be selected... <id="output"></p>
    

    Use this instead:

    <div id="output">
        <p>Waiting for the location to be selected... </p>
    </div>
    

    document.getElementById("output") is looking for an element with an id attribute with a value of "output", not an id element.

    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败