php - 包含 MySQL 内容的 Bootstrap 数据表

标签 php mysql twitter-bootstrap

我有一个表单,用户可以在其中选择烛台的引用。
选择完成后,与烛台相关的事件列表会出现在 Bootstrap 表中。
该表由 Mysql 数据库中的项目完成。

一切正常。现在我想在另一个名为“测试”的列中添加一个按钮。但是我没有按钮..我放了一张我看到的截图..

My test

我的代码是这样的:

表格文件

<?php

require_once 'login.php'; 


$sql= "SELECT ptlum FROM ptlum where ptlum LIKE '%AZ%'";
$result = mysql_query($sql) or die("Requete pas comprise"); 

         //while($data = mysql_fetch_array($result)) 
       // { 
        //echo "<option>".$data[ptlum]."</option>"; 
       // }

?>

<html>
<head>
    <meta charset="utf-8">
    <link href="examples.css" rel="stylesheet">
    <link href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/lib/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/custom.css" rel="stylesheet">
    <link href="bootstrap.table.css" rel="stylesheet">



<script>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else { 
        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("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>
</head>
<body>

<form class="form-horizontal" >

<legend>Rechercher une panne en cours ou archivée</legend>

<div class="control-group">
  <label class="control-label" for="selectbasic-0">Sélectionner un point lumineux</label>
  <div class="controls">
<select name="users" onchange="showUser(this.value)">
<?php 
while ($row = mysql_fetch_array($result))
{
    echo "<option>".$row[ptlum]."</option>";
}
?> 
  </select>
    </div>
</div>
</form>


    <script src= "jquery.js"></script>
    <script src= "bootstrap.min.js"></script>
    <script src= "bootstrap.table.js"></script>

<br>
<div id="txtHint"><b></b></div>

</body>
</html>

调用数据库的 PHP 文件

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <link href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet">

</head>
<body>

    <script src= "jquery.js"></script>
    <script src= "https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
    <script src= "https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>



<?php
$q = $_GET['q'];
//echo $q;

$con = mysqli_connect('localhost','root','root','sdeer');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM depannages WHERE ptlum = '".$q."'";
$result = mysqli_query($con,$sql);



echo "<table id=\"example\" class=\"table table-striped table-bordered\" cellspacing=\"0\" width=\"100%\">
<tr>
<th>Pt Lum</th>
<th>Matériel</th>
<th>Prestation</th>
<th>Date</th>
<th>Nature</th>
<th>Test</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tbody>";    
    echo "<tr>";
    echo "<td>" . $row['ptlum'] . "</td>";
    echo "<td>" . $row['materiel'] . "</td>";
    echo "<td>" . $row['presta'] . "</td>";
    echo "<td>" . $row['date'] . "</td>";
    echo "<td>" . $row['nature'] . "</td>";        
    echo "</tr>";
    echo "</tbody>";    

}
echo "</table>";



mysqli_close($con);

?>

<script>

$(document).ready(function() {
    var table = $('#example').DataTable( {
        "columnDefs": [ {
            "targets": -1,
            "data": null,
            "defaultContent": "<button>Click!</button>"
        } ]
    } );


</script>

</body>



</html>

如果我想要一个按钮,如何制作?当用户单击该按钮时,将出现一个新窗口。
谢谢!

最佳答案

您可以使 anchor 标记看起来像按钮。只需添加 role="button"

<a href="Give-Some-Page-URL-Here.php" class="btn btn-default" role="button" target="blank">New Window Button</a>

编辑代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet">
<script src= "jquery.js"></script>
<script src= "https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script src= "https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>
</head>
<body>
    <?php
    $q = $_GET['q'];
    $con = mysqli_connect('localhost','root','root','sdeer');
    if (!$con) {
        die('Could not connect: ' . mysqli_error($con));
    }
    mysqli_select_db($con,"ajax_demo");
    $sql="SELECT * FROM depannages WHERE ptlum = '$q'";
    $result = mysqli_query($con,$sql);
    ?>
    <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Pt Lum</th>
                <th>Matériel</th>
                <th>Prestation</th>
                <th>Date</th>
                <th>Nature</th>
                <th>Test</th>
            </tr>
        </thead>
        <tbody>
        <?
        while($row = mysqli_fetch_array($result))
        {?>
            <tr>
                <td><?echo $row['ptlum'];?></td>
                <td><?echo $row['materiel'];?></td>
                <td><?echo $row['presta'];?></td>
                <td><?echo row['date'];?></td>
                <td><?echo $row['nature'];?></td>       
                <td>
                    <a href="Give-Some-Page-URL-Here.php" class="btn btn-default" role="button" target="blank">New Window Button</a>
                </td> 
            </tr>
        <?}?>
        <tbody>
    </table>


    <?mysqli_close($con);?>

    <script>

    $(document).ready(function() {
        var table = $('#example').DataTable( {
            "columnDefs": [ {
                "targets": -1,
                "data": null,
                "defaultContent": "<button>Click!</button>"
            } ]
        } );


    </script>
</body>
</html>

关于php - 包含 MySQL 内容的 Bootstrap 数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33263518/

相关文章:

mysql - 单选查询处理两种情况

PHP MYSQL : how to keep the variable alive till connection ends

mysql 选择行然后复制行并更新值

php - Magento:在特殊 View 上进行分层导航

php - Doctrine 2 动态查询

twitter-bootstrap - Bootstrap - 折叠带有 'special' 属性的项目

javascript - Bootstrap 表单输入浮点值问题

javascript - RateIt jquery 插件与我项目中的 jquery 文件发生冲突?

php - 如何在每个请求的根 URL 后添加一个单词?

php - 使用 PDO 准备 SQL 语句