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

dongliang2005
dongliang2005 1)您想要在新窗口中显示的任何内容。你要显示哪个页面?2)您想在新窗口中打开按钮。
大约 5 年之前 回复

1个回答

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>
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问