Hallo zusammen,
ich bediene mich einer MySQl Datenbank um Inhalte in einer Tabelle anzuzeigen wie der nachfolgende Screenshot zeigt.
html-seminar.de/woltlab/attachment/2956/
Alle Produkte die "aktiv" sind haben den INT Wert 1 in der Datenbank. Da die Zahl 1 etwas doof aussieht würde ich das gerne optisch etwas aufwerten und mit einem bootstrap "Switch" arbeiten.
Leider gelingt es mir nicht den Switch so einzubinden das dieser a, angezeigt wird und b, die Zahl 1 als aktiv interpretiert und die Zahl 0 als inaktiv
Nachfolgend ein Teil des SourceCodes dazu, ich komme leider nicht weiter.
Habt ihr eine Idee?
PHP
<h2><?php echo $products['headline']; ?>
<a href="#"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true" data-toggle="modal" data-target="#modal_artikel_hinzufuegen"></span></a>
</h2>
<p class="help-block"><?php echo $products['help']; ?></p>
<br>
<table id="products" class="table tablesorter">
<thead>
<tr>
<th># ID</th>
<th><?php echo $products['barcode']; ?></th>
<th><?php echo $products['name']; ?></th>
<th><?php echo $products['price']; ?></th>
<th><?php echo $products['stock']; ?></th>
<th><?php echo $products['active']; ?></th>
<th><?php echo $products['picture']; ?></th>
<th><?php echo $products['actions']; ?></th>
<th><input id="kv-toggle-demo" type="checkbox" checked data-toggle="toggle" data-on="Active" data-off="Due" data-onstyle="success" data-offstyle="warning"></th>
</tr>
</thead>
<tbody>
<?php
include("inc/db_connect.php");
$page = 1;
if(isset($_GET['page'])) {
$page = intval($_GET['page']);
}
$entries_per_page = 10;
$start = ($page-1) * $entries_per_page;
$stmt = $dbh->prepare("SELECT * FROM products LIMIT :start, :limit");
$stmt->bindParam(':start', $start, PDO::PARAM_INT);
$stmt->bindParam(':limit', $entries_per_page, PDO::PARAM_INT);
$stmt->execute();
while($row = $stmt->fetch())
{
echo "<tr>";
echo "<td>" . $row['p_id'] . "</td>";
echo "<td>" . $row['barcode'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['stock'] . "</td>";
echo "<td>" . $row['active'] . "</td>";
echo "<td><img src=\"/Login-System/" . $row['dateiname'] . "\" alt=\"...\" class=\"img-responsive\" width=\"60px\"></td>";
echo "<td><a href=\"#\"><span class=\"glyphicon glyphicon-pencil\" aria-hidden=\"true\" data-toggle=\"modal\" data-target=\"#modal_artikel_bearbeiten\" data-id=\"".$row['p_id']."\"></span></a>
<a href=\"/Login-System/artikel/loeschen/".$row['p_id']."\" onclick=\"return confirm('Möchten Sie diesen Artikel wirklich löschen?');\"><span class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></span></a></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<div class="modal fade" id="modal_artikel_hinzufuegen" tabindex="-1" role="dialog" aria-labelledby="label_artikel_hinzufuegen">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="label_artikel_hinzufuegen"><?php echo $products['new']; ?></h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="barcode_neu"><?php echo $products['barcode']; ?></label>
<input type="text" id="barcode_neu" class="form-control" placeholder="<?php echo $products['barcode']; ?>">
</div>
<div class="form-group">
<label for="name_neu"><?php echo $products['name']; ?></label>
<input type="text" id="name_neu" class="form-control" placeholder="<?php echo $products['name']; ?>">
</div>
<div class="form-group">
<label for="price_neu"><?php echo $products['price']; ?></label>
<input type="number" step="0.01" id="price_neu" class="form-control" placeholder="<?php echo $products['price']; ?>">
</div>
<div class="form-group">
<label for="stock_neu"><?php echo $products['stock']; ?></label>
<input type="text" id="stock_neu" class="form-control" placeholder="<?php echo $products['stock']; ?>">
</div>
<div class="form-group">
<label for="bild_neu"><?php echo $products['picture']; ?></label>
<input type="file" id="bild_neu" accept="image/*">
<p class="help-block"><?php echo $products['pic_desc']; ?></p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $btn['abort']; ?></button>
<button type="button" class="btn btn-primary" id="btn_artikel_hinzufuegen"><?php echo $btn['save']; ?></button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modal_artikel_bearbeiten" tabindex="-1" role="dialog" aria-labelledby="label_artikel_bearbeiten">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="label_artikel_bearbeiten"><?php echo $products['edit']; ?></h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="barcode_bearbeiten"><?php echo $products['barcode']; ?></label>
<input type="text" id="barcode_bearbeiten" class="form-control" placeholder="<?php echo $products['barcode']; ?>">
</div>
<div class="form-check form-switch">
<input type="checkbox" name="checkbox1">
<label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
</div>
<div class="form-group">
<label for="name_bearbeiten"><?php echo $products['name']; ?></label>
<input type="text" id="name_bearbeiten" class="form-control" placeholder="<?php echo $products['name']; ?>">
</div>
<div class="form-group">
<label for="price_bearbeiten"><?php echo $products['price']; ?></label>
<input type="number" step="0.01" id="price_bearbeiten" class="form-control" placeholder="<?php echo $products['price']; ?>">
</div>
<div class="form-group">
<label for="stock_bearbeiten"><?php echo $products['stock']; ?></label>
<input type="text" id="stock_bearbeiten" class="form-control" placeholder="<?php echo $products['stock']; ?>">
</div>
<div class="form-group">
<label for="bild_bearbeiten"><?php echo $products['picture']; ?></label>
<input type="file" id="bild_bearbeiten" accept="image/*">
<p class="help-block"><?php echo $products['pic_desc']; ?></p>
<div id="bild_hinterlegt"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $btn['abort']; ?></button>
<button type="button" class="btn btn-primary" id="btn_artikel_bearbeiten"><?php echo $btn['save']; ?></button>
</div>
</div>
</div>
</div>
<?php
if(isset($_GET['id'], $_GET['aktion']))
{
if($_GET['aktion'] == "loeschen")
{
include("inc/db_connect.php");
$k_id = $_GET['id'];
$stmt2 = $dbh->prepare("DELETE FROM products WHERE p_id = :p_id");
$stmt2->bindParam(':p_id', $k_id);
$stmt2->execute();
?>
<script>
window.location = "/Login-System/artikel";
</script>
<?php
}
}
?>
<script src="/Login-System/js/jquery.tablesorter.min.js"></script>
<script src="/Login-System/js/bootstrap-switch.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(function(){
$("#products").tablesorter();
});
$("[name='checkbox1']").change(function() {
if(!confirm('Bist du sicher?')) {
this.checked =true;
}
});
$("[name='checkbox1']").bootstrapSwitch({
on: 'Ein',
off: 'Aus ',
onLabel: ' ',
offLabel: ' ',
same: false,//same labels for on/off states
size: 'sm',
onClass: 'primary',
offClass: 'default'
});
Alles anzeigen