dsa1230000 2015-10-21 15:37
浏览 185

带有MySQL内容的Bootstrap数据表

I have a form in which a user select a reference of a candelabra.
When the choice done, a list of incidents relative to the candelabra appears in a bootstrap table.
The table is completed with items from a Mysql database.

All is ok. Now I'd like to add a button in another column called "test". But I have no buttons.. I put a screenshot of what I see..

My test

My code is this one :

FORM FILE

<?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 FILE WITH CALLING THE DATABASE

<!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>

How to make it if I want to have a button ? When the user will click on the button, a new window will appear.
Thanks !

  • 写回答

1条回答 默认 最新

  • dongpai9986 2015-10-21 18:24
    关注

    You can make a anchor tag look like as button. Just you need to add role="button".

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

    Edited Code:

    <!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>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题