I try to output a database Table in PHP within a HTML Table. When I view the output in HTML, It is totally messed up. In my opinion everything is correct. Maybe someone of you see the mistake.
My PHP file:
<table id="table_id" class="display table table-hover table-responsive table-striped">
<thead>
<tr>
<th class="col-md-3">Gespeichert am</th>
<th class="col-md-5">Text</th>
<th class="col-md-3">Kategorie</th>
<th class="col-md-1"><span class='glyphicon glyphicon-remove' aria-hidden='true'></span></th>
</tr>
</thead>
<tbody>
<?php
while($row=mysql_fetch_object($ergebnis))
{
echo "<tr>";
echo "<td>".date("H:i - d.m.y",strtotime($row->Zeit) + 60*60)."</td>";
echo "<td><a href='".$row->url."' target='_blank'>".$row->text."</a></td>";
echo "<td>".$row->kategorie."</td>";
echo "<form action='delete.php' method='post'>";
echo "<td>";
echo "<input type='hidden' name='delete_id' value='".$row->id."'</td>";
echo "<button onClick='submit();' style='border:none; background-color:transparent; padding:0px;' type='submit' value='Delete'><span class='glyphicon glyphicon-remove delete' aria-hidden='true'></span></button>";
echo "</td>";
echo "</form>";
echo "</tr>";
}
?>
</tbody>
</table>
My output in HTML looks like this:
<table id="table_id" class="display table table-hover table-responsive table-striped">
<thead>
<tr>
<th class="col-md-3">Gespeichert am</th>
<th class="col-md-5">Text</th>
<th class="col-md-3">Kategorie</th>
<th class="col-md-1"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td>15:46 - 26.03.15</td>
<td>Google link</td>
<td>Web</td>
<form action="delete.php" method="post"></form>
<td><input type="hidden" name="delete_id" value="37" <="" td="">
<button onclick="submit();" style="border:none; background-color:transparent; padding:0px;" type="submit" value="Delete">
<span class="glyphicon glyphicon-remove delete" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>
Either put <form> inside cell of table (inside the <td>), or wrap it around entire table.
The problem is that <tr> allows only <th> and <td> nodes inside and that's why your <form> is getting messed up.
Also, as someone already mentioned in comments, the following line has errors which result in broken html:
echo "<input type='hidden' name='delete_id' value='".$row->id."'</td>";
should be:
echo "<input type='hidden' name='delete_id' value='".$row->id."'></td>";
Related
I am trying to print a table with the list of customer oder from data retrieved from an xml file. I think my attempt at retrieving data has failed as it did not show anything. I also wanted to add two buttoms at the end of each order (delet and edit):
<?php
// Loading the XML file
$xml = simplexml_load_file("database/orderlist.xml");
echo "
<div style='overflow-x:auto;'>
<table id='order'>
<tr>
<th>Order #</th>
<th>Customer ID# </th>
<th>Items</th>
<th>Total Prices (CND)</th>
</tr>
foreach($xml->children() as $ftpxml)
{
echo '<td>".$ftpxml->attributes()->id."</td>';
echo '<td> ".$ftpxml->attributes()->customerID." </td>';
echo '<td>".$ftpxml->attributes()->products." </td>';
echo '<td>".$ftpxml->attributes()->totalprice." </td>';
echo '<a href="backStoreOrderProfile.html" ><button class="btn Edit" id="btn" input value="Check" type=submit > Edit </button></a>';
echo '<button class="btn Delete" id="btn" input value="Check" type=submit > Delete</button></td>';
}
</table>
</div>
";
?>
You have a number of problems in your codes
make sure you end each php statement by a semi-colon
make sure you enclose the string in same quotation marks
make sure you traverse the XML hierarchy properly
<?php
// Loading the XML file
$xml = simplexml_load_file("database/orderlist.xml");
echo "
<div style='overflow-x:auto;'>
<table border=1 cellpadding=5 id='order' style='border-collapse: collapse;' bordercolor='#DDDDDD'>
<tr>
<th>Order #</th>
<th>Customer ID# </th>
<th>Items</th>
<th>Total Prices (CND)</th>
<th>Edit
<th>Delete
</tr>";
foreach ($xml->oder as $ftpxml) {
?>
<tr>
<td><?php echo $ftpxml->id; ?>
<td><?php echo $ftpxml->customerID; ?>
<td>
<?php
foreach ($ftpxml->products->product as $ftpxml2) {
echo $ftpxml2->productName . " ";
} ?>
<td>
<?php echo $ftpxml->totalprice; ?>
<?php
echo '<td><a href="backStoreOrderProfile.html" ><button class="btn Edit" id="btn" input value="Check" type=submit > Edit </button></a>';
echo '<td><button class="btn Delete" id="btn" input value="Check" type=submit > Delete</button></td>';
?>
<?php
} ?>
I am buildingd a library management system in PHP and HTMl.
I have some problem with the borrowing system where user can borrow books.
Here is my emitere-carti.php:
<form action="imprumutare.php" method="POST">
<table class="table table-dark">
<thead>
<tr>
<th>Imprumutare</th>
<th scope="col">Titlu </th>
<th scope="col">Autor</th>
<th scope="col">Categorie</th>
<th scope="col">Stoc</th>
</tr>
</thead>
<tbody>
<?php
$selectare="SELECT * FROM carti";
$rezultat=mysqli_query($conn,$selectare);
if(mysqli_num_rows($rezultat)>0){
while($row=mysqli_fetch_assoc($rezultat)){
$carte_nume=$row['titlu'];
$disabled=$row['stoc']>0 ? "" :"disabled";
?>
<tr>
<td><input type="submit" name="test" class="btn btn-secondary"
value="Imprumutare" <?php echo $disabled;?>></input>
<td><input type="text" name="nume" value="<?php echo $row['titlu'];?
>"></input></td>
<td><?php echo $row['autor'];?></td>
<td><?php echo $row['categorie'];?></td>
<td><?php echo $row['stoc'];?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</form>
Here is my imprumutare.php(that means borrowing):
include('conexiune.php');
//sfarsit if
//Imprumutare
if(isset($_POST['test'])){
$id=$_POST['identificator'];
$nume_carte=$_POST['nume'];
$sql_rezervare="UPDATE carti SET stoc=stoc-1 WHERE
titlu='$nume_carte' ";
if( mysqli_query($conn,$sql_rezervare)){
header('location:emitere_carti.php');
}
else{
die(mysqli_error($conn));
}
}
Here is a screenshot about what I am talking:
So my problem is both buttons are decrementeing the same value(the value of stoc).
Can someone help me?
Form with download.php - does not work
Form with action with remove.php - works
Am I missing some little thing?
<table id="mytable1" width="80%" class="text-center table table-striped table-bordered table-Responsive ">
<thead>
<th>File Name</th>
<th>File Type</th>
<th>File Size(KB)</th>
<th>Remove</th>
<th>Download</th>
</thead>
</tr>
<?php
while($item = mysql_fetch_array($result1)) {
echo "<tr>";
echo "<td>".$item['file_name']."</td>";
echo "<td>".$item['file_type']."</td>";
echo "<td>".$item['file_size']."</td>";
// this command does not work but the next echo works - why?
echo "<td><form action='download.php' method='GET'><input name='filename' type='hidden' value='".$item['file_name']."'/><button class='btn btn-danger btn-xs' type='submit' value='down'/><span class='glyphicon glyphicon-trash'></span></form></td>";
echo "<td><form action='remove.php' method='GET'><input name='filename' type='hidden' value='".$item['file_name']."'/><button class='btn btn-primary btn-xs' type='submit' value='del'/><span class='glyphicon glyphicon-download'></span></form></td>";
echo "</tr>";
}
echo "</table>";
?>
I found this plugin JQuery.FilterTable for searching on a table bun when i put at my table doesn't work .
I don't know what is the problem but from my opinion i think is because the table is made with PHP and the datas for table are from database.
The code lis like this:
<div class="issue-table">
<table class="table table-striped" id="data-table">
<thead>
<tr>
<th scope="col" title="President Number">Nr:</th>
<th scope="col">Brand</th>
<th scope="col">Model</th>
<th scope="col">Color</th>
<th scope="col">Release date</th>
<th scope="col">Price</th>
<?php
if ($user->data()->type == 1) {
echo "<th>Delete</th>";
}
?>
</tr>
</thead>
<tbody>
<?php
$x = 1;
foreach ($car as $index => $car_val) {
$cars = DB::table('brands')->get(['id','=',$car_val->id_make]);
$car_name = $cars->first()->name;
echo "<tr>";
echo "<td>".$x++."</td>";
echo "<td>".$car_name."</td>";
echo "<td>".$car_val->model."</td>";
echo "<td>".$car_val->color."</td>";
echo "<td>".$car_val->release_date."</td>";
echo "<td>".$car_val->value."</td>";
if ($user->data()->type == 1) {
echo
"<td>
<form action='index.php?page=carlist' method='POST'>
<input type='hidden' value='".$car_val->id."' name='id'>
<input type='submit' value='X' class='btn btn-danger'>
</form>
</td>";
}
echo "</tr>";
}
?>
</tbody>
</table>
I used this code but isn't working:
<script>
$('table').filterTable();
</script>
How can I make this plugin to work?
Heres my code: HTML with Server side to get data from the database. How do I get id from the datatables using checkbox option?
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<h4>
<th></th> <!-- For checkbox column-->
<th>ID Number</th>
<th>Lastname</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Gender</th>
<th>Course</th>
<th>Department</th>
<th>Address</th>
<th>Contact</th>
<th>Birthdate</th>
<th>View</th>
<th>Events</th>
</h4>
</tr>
</thead>
<tbody>
<?php
include 'pgconnect.php';
$mydata = mysqli_query($conn,"SELECT * FROM student") or die(mysql_error());
while($record = mysqli_fetch_assoc($mydata))
{
$id=$record['id'];
?>
<tr>
<td><input type="checkbox"></td>
<td class="id"><?php echo $record['id'] ?></td>
<td class="lname"><?php echo $record['last_name'] ?></td>
<td class="fname"><?php echo $record['first_name'] ?></td>
<td class="mname"><?php echo $record['mid_name'] ?></td>
<td class="sex"><?php echo $record['gender'] ?></td>
<td class="course"><?php echo $record['course'] ?></td>
<td class="dept"><?php echo $record['department'] ?></td>
<td class="add"><?php echo $record['home_address'] ?></td>
<td class="contact"><?php echo $record['contact'] ?></td>
<td class="bdate"><?php echo $record['birthdate'] ?></td>
<td> View Records </td>
<td> <a title='Click here to update record.'href='#edit' data-toggle='modal'><i class="fa fa-pencil fa-fw"></i></a>
<a title='Click here to add record.' href='#'><i class="fa fa-plus fa-fw"></i></a>
<a title='Click here to delete record.' href='delete.php?del=<?php echo $record['id'] ?>'><i class="fa fa-trash-o fa-fw"></i></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Here's my script:
$(document).ready(function(){
$('#dataTables-example').dataTable();
});
I tried to get the ID but still it didn't works. Hope you can help me.
In your work, you get the ID in table. your should grab it from the checkbox if you use jquery, as in;
<script>
$(document).ready(function(){
document.getElementByID("ckmyid").innerHTML;
});
</script>
Note:add Selector ID in your checkbox, first, say, "ckmyid" so the code will be like this:
<input id="ckmyid" type="checkbox" value="<?php echo $record['id'] ?>">
Based on your structure, you can grab it directly from the link in your view records link if you want to place the ID there,as in;
<td> View Records </td>