The following code adds a Accept/Decline Button per row. But for some reason, the decline button does not appear. I dont know whats wrong. Been stuck for a while now. Help would be appreciated. Thanks!!
<?php
$con=mysqli_connect("localhost","root","","rabco");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM service_request");
echo "<table border='1'>
<tr>
<th>Service ID</th>
<th>Service Type</th>
<th>Schuduled Date</th>
<th>Scheduled Time</th>
<th>Client Reference
<th>Client ID</th>
<th>Admin ID</th>
<th>Special Instructions</th>
<th>Status</th>
<th>Approve</th>
<th>Decline</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Service_ID'] . "</td>";
echo "<td>" . $row['Service_type'] . "</td>";
echo "<td>" . $row['Sched_date'] . "</td>";
echo "<td>" . $row['Sched_time'] . "</td>";
echo "<td>" . $row['Client_reference'] . "</td>";
echo "<td>" . $row['Client_IDN'] . "</td>";
echo "<td>" . $row['Admin_IDN'] . "</td>";
echo "<td>" . $row['Special_instructions'] . "</td>";
echo "<td>" . $row['Request_status'] . "</td>";
echo "<td>Approve</td>";
echo "<td>Decline</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
You are missing the closing quotes on your href attributes, which is creating malformed HTML output.
You need to change:
echo "<td>Approve</td>";
echo "<td>Decline</td>";
to
echo "<td><a href='approve.php?Service_ID=".$row['Service_ID']."'>Approve</a></td>";
echo "<td><a href='decline.php?Service_ID=".$row['Service_ID']."'>Decline</a></td>";
There is a missing closing quote here:
echo "<td>Approve</td>";
Change to:
echo "<td><a href='approve.php?Service_ID=".$row['Service_ID']."'>Approve</a></td>";
Related
I firstly did the table layout and made sure everything is working, after connecting the table to a database and trying to put the records inside it, everything worked perfectly, but the class didnt, i have now the boring table without the layout made.
<body>
<h1>Employees</h1>
<table class="responstable">
<?php
require 'connection.php';
$conn = Connect();
$result = mysqli_query($conn,"SELECT * FROM employee");
echo "<table border='1'>
<tr>
<th>Id</th>
<th>First name</th>
<th>Last name</th>
<th>Salary</th>
<th>Start Date</th>
<th>Department</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['salary'] . "</td>";
echo "<td>" . $row['startdate'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
<script src='http://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'></script>
</body>
</html>
the table class is "responstable"
table tag is defined in 2 places.try removing this.
echo "<table border='1'>
or remove the table tag at the top after h1 tag and add the class to the table tag defined in the echo as,
complete code
<body>
<h1>Employees</h1>
<?php
require 'connection.php';
$conn = Connect();
$result = mysqli_query($conn,"SELECT * FROM employee");
echo "<table border='1' class='responstable'>
<tr>
<th>Id</th>
<th>First name</th>
<th>Last name</th>
<th>Salary</th>
<th>Start Date</th>
<th>Department</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['salary'] . "</td>";
echo "<td>" . $row['startdate'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
<script src='http://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'></script>
</body>
</html>
So this is my simple php code just to output them on a simple table. I was hoping I make it a sortable table and i do not understand most of the sources from online. Could someone show me a simple or at least the way to do it? I could also go for a drop down menu to select how to list the following data columns!
$connect = mysql_connect("localhost","root","");
if(!$connect){
die("Can not connect: " . mysql_error());
}
mysql_select_db("safedrive", $connect);
$sql = "SELECT * FROM users";
$myData = mysql_query($sql,$connect);
echo "<table border=1>
<tr>
<th>ID</th>
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
<th>Model</th>
<th>Year</th>
<th>Plate Number</th>
<th>City</th>
<th>Country</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . $record['email'] . "</td>";
echo "<td>" . $record['firstName'] . "</td>";
echo "<td>" . $record['lastName'] . "</td>";
echo "<td>" . $record['model'] . "</td>";
echo "<td>" . $record['Year'] . "</td>";
echo "<td>" . $record['plateNumber'] . "</td>";
echo "<td>" . $record['city'] . "</td>";
echo "<td>" . $record['country'] . "</td>";
echo "<br />";
}
echo "</table>";
I understand it is probably better done in the HTML tag, but I would like to hear some proper opinions.
Use this : TableSorter 2.0 , you just need to install the plugin and configure a bit the js file. All is well explained on the site
Trying to add tablesorter added to a page I am creating. I know very little of jquery, so I'm guessing that's where my fault is. I've added the required code in the <head> area of my page, and made the necessary changes to my table. My table still renders as it would with just HTML. Ideas?
<html>
<head>
<title>Inventory</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="http://tablesorter.com/__jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ $("table").tablesorter(); });
</script>
</head>
<body>
<?php
$con=mysqli_connect("localhost","user","pass","db_name");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT
products.name,
products.sku,
inventory.quantityfry,
inventory.quantityjuv,
inventory.quantityadult,
inventory.notes,
inventory.location,
inventory.owner
FROM
products
INNER JOIN
inventory
ON
products.sku=inventory.sku";
$result = mysqli_query($con,$query) or die(mysqli_error($con));
echo "<table border='1' id='table' class='tablesorter'>
<thead>
<tr>
<th>Species</th>
<th>SKU</th>
<th>Fry Count</th>
<th>Juvie Count</th>
<th>Adult Count</th>
<th>Notes</th>
<th>Location</th>
<th>Owner</th>
</tr>
</thead>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['sku'] . "</td>";
echo "<td>" . $row['quantityfry'] . "</td>";
echo "<td>" . $row['quantityjuv'] . "</td>";
echo "<td>" . $row['quantityadult'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['owner'] . "</td>";
echo "</tr>";
echo "</tbody>";
}
mysqli_free_result($result);
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Thanks!
Three things:
Don't link directly to tablesorter at tablesorter.com - make a copy to your own server, or use a copy at a CDN (this is of my fork of tablesorter at cdnjs.com).
Include a <!DOCTYPE html> at the top of your HTML otherwise IE will change into quirks mode and pretty much make your site look bad.
As #MikeB mentioned, the above code wraps every row in a tbody, correct the code as follows (this is just a snippet):
echo "<table border='1' id='table' class='tablesorter'>
<thead>
<tr>
<th>Species</th>
<th>SKU</th>
<th>Fry Count</th>
<th>Juvie Count</th>
<th>Adult Count</th>
<th>Notes</th>
<th>Location</th>
<th>Owner</th>
</tr>
</thead><tbody>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['sku'] . "</td>";
echo "<td>" . $row['quantityfry'] . "</td>";
echo "<td>" . $row['quantityjuv'] . "</td>";
echo "<td>" . $row['quantityadult'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['owner'] . "</td>";
echo "</tr>";
}
mysqli_free_result($result);
echo "</tbody></table>";
Having an issue with the output of records from a query run to display records.... It only shows the first row as the code specifies and then the next results all in.. paragraphs? I don't know if it has something to do
<?php
include 'core/init.php';
include 'includes/overall/header.php';
?>
<div class="article" style="width:900px !important">
<?php
$result = $sql = mysql_query("SELECT * FROM ref_employees WHERE employerid={$user_data['user_id']} ")
or die('Error in query : $sql. ' .mysql_error());
echo "<table border='0' class='table'>
<tr>
<th>ID Number</th>
<th>Employee Number</th>
<th>FirstName</th>
<th>LastName</th>
<th>MiddleName</th>
<th>Job Title</th>
<th>Employement Status</th>
<th>Contact</th>
<th>Email</th>
<th>Edit</th>
</tr>";
if (mysql_num_rows($sql) > 0)
{
while ($row = mysql_fetch_array($sql)){
if ($row['employed'] == '1'){
echo "<tr>";
echo "<td>" . $row['idnumber'] . "</td>";
echo "<td>" . $row['empnumber'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['middlename'] . "</td>";
echo "<td>" . $row['jobtitle'] . "</td>";
echo "<td>" . $row['employed'] . "</td>";
echo "<td>" . $row['contactnum'] . "</td>";
echo "<td>" . $row['contactemail'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "</tr>";
echo "</tr>";
echo "</table>";
}
}
}
?>
</div>
<?php include 'includes/overall/footer.php';
?>
You are using closing table tag into loop as
while ($row = mysql_fetch_array($sql)){
....
....
...
echo "</table>";
}
use table closing tag out of loop as
while ($row = mysql_fetch_array($sql)){
....
....
...
}
echo "</table>";
im making some application form in PHP.
im putting all info returned from the database into a table.
Now i want to create a button on each line that changes something in the DB of that line.
but i have no idea to do that :S
Thank you!
echo "<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>age</th>
<th>position</th>
<th>experience</th>
<th>motivation</th>
<th>date</th>
<th>status</th>
<th>test</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['position'] . "</td>";
echo "<td>" . $row['exp'] . "</td>";
echo "<td>" . $row['motivation'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . '<input type="submit" name="submit" value="accept">' . "</td>";
echo "</tr>";
}
echo "</table>";
EDIT: get it working using another script:
echo "<td>Approve</td>";
and edit.php:
<?php
include("dbconnect.php");
$member_id = $_GET['id'];
$status = $_GET['status'];
echo $member_id;
echo $status;
if ($status == 'app')
$query = "update apps set status = 'approved' where id = $member_id";
mysql_query($query) or die (mysql_error());
?>
Create small form with parameters in the cell you want the button to do smth. This is the simpliest approach (approach with refresh).
One more solution is to use AJAX on button click and forward action to some endpoint. This way it would be dynamic and probably what you are want to implement.
echo "<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>age</th>
<th>position</th>
<th>experience</th>
<th>motivation</th>
<th>date</th>
<th>status</th>
<th>test</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['position'] . "</td>";
echo "<td>" . $row['exp'] . "</td>";
echo "<td>" . $row['motivation'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . '<form type="POST"><input type="hidden" name="whatever" value="$row['id']"><input type="submit" name="submit_btn" value="accept"></form>' . "</td>";
echo "</tr>";
}
echo "</table>";
in this way, you could get a form in each row of the table. Now, you just need to use php POST function.
if(isset($_POST['submit_btn']))
{
//whatever u need to do
}