I have a table that shows me data from a call flow.
I need the Data from this table to be manipulated per row in such a way that all the values of my table, which are being looked up from my DB, (which are now in code) will be translated into a text value. Let me show U and explain:
My Table:
<?php
include_once "Connect2Martijn1.php";
?>
<link rel="stylesheet" href="CSSMartijn1.css">
</link>
<head>
<meta charset="iso-8859-1">
<meta name="description"content="VoizXL ">
<meta name="keywords"content="VoizXL ">
<meta name="author"content="Kenn Lo-A-Tjong">
</meta>
<title>Call Flow</title>
</head>
<fieldset>
<article class="rondehoeken">
<header>
<div class="streep1"></div>
<div class="streep2"></div>
<div class="streep3"></div>
<div class="streep4"></div>
<div class="streep5"></div>
<h1 id="artikel-titel" >Call Flow</h1>
</header>
<div id="artikel-container">
<table class="table 1">
<thead>
<title>Call Flow</title>
<meta charset = "UTF-8" />
<style type = "text/css">
table, td, th {
border: 1px solid black;
}
</style>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","root","","voizxl_wachtrij");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Callflow");
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $row['statusAnswered'] . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Example of (how I want to be) Translating the Data:
<?php
if ($row['statusAnswered'] ="NULL")
{
echo "Not Answered!";
}
else
{
echo "Answered!";
}
?>
What I want to Achieve is for eg. that the value in this table from $row['statusAnswered'] will be displayed in text as "Answered or Not Answered" if the Value of this row in the DB is NULL or Not...
How do I do this?
Right now I can only achieve to have 1 echo under the table saying Answered :S
No Idea how to put it per $row.
while($row = mysqli_fetch_array($result))
{
if (!isset($row['statusAnswered']))
{
$answered = "Not Answered!";
}
else
{
$answered = "Answered!";
}
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $answered . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
if ($row['statusAnswered'] =="NULL"||$row['statusAnswered'] =="Null" || $row['statusAnswered'] =="null" || $row['statusAnswered'] =="")
{
echo "<td>Not Answered!</td>";
}
else
{
echo "<td>Answered!</td>";
}
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . ($row['statusAnswered']=='NULL'?'Not Answered!':'Answered!') . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
You could use;
$checkstatus = if($row['statusAnswered'] = NULL) { echo "Not Answered!"; } else {echo "Answered!";};
then call that by replacing;
echo "<td>" . $row['statusAnswered'] . "</td>";
with;
echo "<td>{$checkstatus}</td>"
Related
I am trying to show details in a table and show list of values in drop down list. the values are shown in table but drop down list is not showing the values although the values exists and when i save it in session and print it, it appears at the top . Also I have problem in using name of select. when i click on button and wants to read the post value of the option, it gives me error as shown in figure
here is the code:
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value=";
$name ;
echo "> ";
$_SESSION["tt"]=$name;
$name;
echo"</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
Here is my full page code.
<html>
<head>
<title> Expert System </title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:700,600' rel='stylesheet' type='text/css'>
</head>
<body>
<div >
<table id="cells2" border="0" cellpadding="15" cellspacing="5" font size="6">
<tr>
<th><img id="header2" src="images/Kuwait_University_Logo.jpg" > </th>
<th>KUWAIT UNIVERSITY</th>
</tr>
</table>
<div class='back1'>
<table border='1' align='center' id='customers' >
<?php
require "init.php";
session_start();
global $con,$users,$dr_id,$sub_id,$dr_name,$sub_name,$days,$fav,$timing;
global $dr_ide,$dr_namee,$sub_namee,$dayse,$fave,$timinge;
$query= "SELECT * FROM subjects_current where subjects_current.sub_ID NOT IN (SELECT test.subject_id from test)";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else {
while($row = mysqli_fetch_array($result))
{
$IDs[]=$row['sub_ID'];
$Names[]=$row['Name'];
//echo $row['Name'];
}
}
$query= "SELECT * FROM test order by dr_id";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else { echo "
<tr>
<th>Professor Name</th>
<th>First Choice</th>
<th>Second Choice</th>
<th>Third Choice</th>
<th>Fourth Choice</th>
<th>Fifth Choice</th>
<th>Update Subject</th>
</tr>";
$r=0;
$f=0;
while($row = mysqli_fetch_array($result))
{
$dr_ide[$f]=$row['dr_id'];
$dr_namee[$f]=$row['dr_name'];
$sub_namee[$f]=$row['sub_name'];
$dayse[$f]=$row['days'];
$timinge[$f]=$row['timing'];
$fave[$f]=$row['fav'];
//echo "<tr>";
//echo "<td> Dr. " . $dr_namee[$f] . "</td>";
//echo "<td>" . $sub_namee[$f] . "</td>";
//echo "<td>" . $fave[$f] . "</td>";
//echo "<td>" . $dayse[$f] . "</td>";
//echo "</tr>";
//$r++;
$f++;
}
//for($i=0;$i<count($Names);$i=$i+5)
//{
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value='$name'>$name</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
?>
</table>
<form method='post' action='edit_subjects.php'>
<input ID="btn2" name="confirm" type="submit" value="Home">
</form>
</div>
</body>
</html>
Remove name='perr' from <options> and change foreach() like below:-
foreach($Names as $name) {
echo"<option value='$name'>$name</option>";
}
Do change in your code like this:-
echo "<form method='post' action='edit_subjects.php'>"; //add before while
while($row = mysqli_fetch_array($result))
{
$dr_ide[$f]=$row['dr_id'];
$dr_namee[$f]=$row['dr_name'];
$sub_namee[$f]=$row['sub_name'];
$dayse[$f]=$row['days'];
$timinge[$f]=$row['timing'];
$fave[$f]=$row['fav'];
$f++;
}
for($i=0;$i<count($dr_ide);$i=$i+5)
{
$dr_nam = $dr_namee[$i];
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td><select name='perr[$dr_nam]' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value='$name'>$name</option>";
}
echo "</select></td>";
echo "</tr>";
}
echo"<input ID='btn2' name='confirm' type='submit' value='Home'></form>"; //add just after while code ended
echo "<td> <select name='perr' >
<option name='perr' selected='selected'> Choose one </option>";
foreach($Names as $name) {
echo"<option name='perr' value='". $name ."'> ". $name ." </option>";
}
echo "</select></td>";
You have to echo the names like this:
foreach($Names as $name) {
echo "<option value=";
echo $name ;
echo "> ";
$_SESSION["tt"]=$name;
echo $name;
echo"</option>";
}
And put the table inside the form:
<html>
<head>
<title> Expert System </title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:700,600' rel='stylesheet' type='text/css'>
</head>
<body>
<div >
<table id="cells2" border="0" cellpadding="15" cellspacing="5" font size="6">
<tr>
<th><img id="header2" src="images/Kuwait_University_Logo.jpg" > </th>
<th>KUWAIT UNIVERSITY</th>
</tr>
</table>
<div class='back1'>
<form method='post' action='edit_subjects.php'>
<table border='1' align='center' id='customers' >
<?php
require "init.php";
session_start();
global $con,$users,$dr_id,$sub_id,$dr_name,$sub_name,$days,$fav,$timing;
global $dr_ide,$dr_namee,$sub_namee,$dayse,$fave,$timinge;
$query= "SELECT * FROM subjects_current where subjects_current.sub_ID NOT IN (SELECT test.subject_id from test)";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else {
while($row = mysqli_fetch_array($result))
{
$IDs[]=$row['sub_ID'];
$Names[]=$row['Name'];
//echo $row['Name'];
}
}
$query= "SELECT * FROM test order by dr_id";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else { echo "
<tr>
<th>Professor Name</th>
<th>First Choice</th>
<th>Second Choice</th>
<th>Third Choice</th>
<th>Fourth Choice</th>
<th>Fifth Choice</th>
<th>Update Subject</th>
</tr>";
$r=0;
$f=0;
while($row = mysqli_fetch_array($result))
{
$dr_ide[$f]=$row['dr_id'];
$dr_namee[$f]=$row['dr_name'];
$sub_namee[$f]=$row['sub_name'];
$dayse[$f]=$row['days'];
$timinge[$f]=$row['timing'];
$fave[$f]=$row['fav'];
//echo "<tr>";
//echo "<td> Dr. " . $dr_namee[$f] . "</td>";
//echo "<td>" . $sub_namee[$f] . "</td>";
//echo "<td>" . $fave[$f] . "</td>";
//echo "<td>" . $dayse[$f] . "</td>";
//echo "</tr>";
//$r++;
$f++;
}
//for($i=0;$i<count($Names);$i=$i+5)
//{
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option value='$name'>$name</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
?>
</table>
<input ID="btn2" name="confirm" type="submit" value="Home">
</form>
</div>
</body>
</html>
I am working on an application to use on an website. The application let you add job offers to a database to post it on the website and on social media. I have done a lot already but now I am trying to make an sort menu. In my database I have 1 row that is called Status. The Status is an enum with the data Open and Closed so I would like to have a sort option. I would like to sort on Open, Closed and all.
I already have a table and I would like to see the changes on that existed table if that is possible but I have no idea how to do this. Can somebody help me with this? I am using HTML, PHP and as database PHPMyAdmin. Here is my code:
<!DOCTYPE HTML>
<html>
<head>
<style>
table {
border-collapse: collapse;
border: 1px solid black;
}
td {
border: 1px solid black;
width: 120px;
}
</style>
</head>
<body>
<h2>Jobs Overview (Admin)</h2>
<form action="/action_page.php">
<select id="sorting">
<option value="All" >All</option>
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
<br><br>
<?php
include 'Connection.php';
echo "<table>";
echo "<tr>";
echo "<th>" . "jid" . "</th>";
echo "<th>" . "role" . "</th>";
echo "<th>" . "type" . "</th>";
echo "<th>" . "availability" . "</th>";
echo "<th>" . "location" . "</th>";
echo "<th>" . "status" . "</th>";
echo "<th>" . "Verwijder?" . "</th>";
echo "</tr>";
$select = "SELECT * FROM test";
$result = mysql_query($select);
if($result) {
} else {
echo "Error! <br>";
echo mysql_error();
}
while($data = mysql_fetch_assoc ($result)) {
echo "<tr>";
echo "<td>" . $data["jid"] . "</td>";
echo "<td> <a href='jobsupdate.php?jid=" . $data["jid"] . "'>" . $data["role"] . " </a></td>";
echo "<td>" . $data["type"] . "</td>";
echo "<td>" . $data["availability"] . "</td>";
echo "<td>" . $data["location"] . "</td>";
echo "<td>" . $data["status"] . "</td>";
echo "<td> <center>Verwijder</center></td>";
}
echo "</tr>";
echo "</table>";
?>
<br><br>
Vacatures Toevoegen
</body>
</html>
Thanks in advance
You can add HTML class to open and closed jobs.
while($data = mysql_fetch_assoc ($result)) {
echo "<tr>";
echo "<td>" . $data["jid"] . "</td>";
echo "<td> <a href='jobsupdate.php?jid=" . $data["jid"] . "'>" . $data["role"] . " </a></td>";
echo "<td>" . $data["type"] . "</td>";
echo "<td>" . $data["availability"] . "</td>";
echo "<td>" . $data["location"] . "</td>";
if ($data["status"] == 0) {
echo "<td class='open'>" . $data["status"] . "</td>";
} else {
echo "<td class='closed'>" . $data["status"] . "</td>";
}
echo "<td> <center>Verwijder</center></td>";
}
echo "</tr>";
echo "</table>";
After, this you have to write a jquery script to hide the jobs .on change.
$('#sorting').on('change', function(){
var status = $('#sorting:selected').val();
if (status == "Open") {
$('.closed').hide();
} else if (status == "Closed") {
$('.open').hide();
} else if (status == "All"){
$('.closed').show();
$('.open').show();
}
});
I hope this solves your problem.
You can make a Ajax post request on select change to get the records and put those records on success in your table.
More about how to do this with Jquery / Ajax here
More about Jquery on change here
So I basically been coding this quick stat shower for my game server, but I want it to ID numbers.
<html>
<head>
<meta charset="utf-8">
<title>ExileMod Stats</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<?php
$con=mysqli_connect("******","******","******","******"); //server address, username, password, dbname
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//check order ascending or descending
if (isset($_GET["order"])) {
$sort = $_GET["order"];
if ($_GET["order"] == "asc"){
$sort = "desc";
$order = "asc";
}
else{
$sort = "asc";
$order = "desc";
}
}
//check filter
if (isset($_GET["name"])) {
$name = $_GET["name"];
}
else {
$name = "name";
}
$list=array('name', 'money', 'score', 'kills', 'deaths', 'uniform', 'vest', 'last_updated_at');
if (in_array($name,$list))
{
//variable ok
}
else
{
$name = "name";
}
$query = mysqli_query($con,"SELECT * FROM account a INNER JOIN player p ON a.uid = p.account_uid ORDER BY a.$name $order");
?><!--//echo "<table border='1'>-->
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<table class="table">
<tr>
<?php echo "<th>Player Name</th>";?>
<?php echo "<th>Money</th>";?>
<?php echo "<th>Score</th>";?>
<?php echo "<th>Kills</th>";?>
<?php echo "<th>Deaths</th>";?>
<?php echo "<th>Uniform</th>";?>
<?php echo "<th>Vest</th>";?>
<?php echo "<th>Last Updated</th>";?>
</tr>
<!--//";-->
<?php
while($row = mysqli_fetch_array($query))
{
?><tr class="danger"><?php
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['money'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['kills'] . "</td>";
echo "<td>" . $row['deaths'] . "</td>";
echo "<td>" . $row['uniform'] . "</td>";
echo "<td>" . $row['vest'] . "</td>";
echo "<td>" . $row['last_updated_at'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
© HeroesOfGaming 2016 - 2017
</div>
</body>
</html>
So what I am trying to do is put numbers so it counts 1 2 3 4 5 6 7 to however many players are selected from the database? Hopefully this makes sense.
You can do like this
<?php
$i = 0; // <--- Added this
while($row = mysqli_fetch_array($query))
{
$i++; // <--- Added this
?><tr class="danger"><?php
echo "<td>". $i . "</td>"; // <--- Added this
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['money'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['kills'] . "</td>";
echo "<td>" . $row['deaths'] . "</td>";
echo "<td>" . $row['uniform'] . "</td>";
echo "<td>" . $row['vest'] . "</td>";
echo "<td>" . $row['last_updated_at'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I am stuck in one of my application module. I have to set multiple delete options in my application.
I have used the below code. The designing is perfectly fine. All what I want to add multiple delete options in it.
Below is the code which I have tried out:
<html>
<head>
<title>Strad Hosting Limited -Web Hosting</title>
<script language="javascript">
function validate()
{
var chks = document.getElementsByName('checkbox[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select at least one.");
return false;
}
return true;
}
</script>
</head>
<body >
<?php
$con=mysqli_connect("localhost","stradsol","D#v,b5TnQ!D!","stradsol_sales");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons");
echo "<form name='form1' method='post' action='' onSubmit='return validate();'>";
echo "<table border='1' style='
background-color: white;'>
<tr>
<th></th>
<th>id</th>
<th style='padding-left: 11px;'>Lead Generated Date </th>
<th>name</th>
<th>email</th>
<th>contacts</th>
<th>requirement</th>
<th style='display:none;'>Company name</th>
<th style='display:none;'>Address</th>
<th>Next Follow-Up date</th>
<th>Final_Details</th>
<th style='display:none;'>Status</th>
<th style='padding-left: 12px; display:none;'>Lead Closed Date</th>
<th>EDIT</th>
<th>Follow-up History</th>
<th>Add Follow-up</th>
<th>Delete Record</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='".$rows['id']."'></td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a href='config_info.php?id=" . $row['id'] . "'>".$row['name']."</a></td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['contacts'] . "</td>";
echo "<td>" . $row['requirement'] . "</td>";
echo "<td style='display:none;'>" . $row['company_name'] . "</td>";
echo "<td style='display:none;'>" . $row['address'] . "</td>";
echo "<td>" . $row['startdate'] . "</td>";
echo "<td>" . $row['final_details'] . "</td>";
echo "<td style='display:none;'>" . $row['status'] . "</td>";
echo "<td style='display:none;'>" . $row['lead_close'] . "</td>";
echo "<td><a href='edit_eg1.php?id=" . $row['id'] . "'>Edit</a></td>";
echo "<td><a href='Follow_history.php?id=" . $row['id'] . "'>Follow_history</a></td>";
echo "<td><a href='add_follow.php?id=" . $row['id'] . "'>Followup</a></td>";
echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
echo "</tr>";
}
echo "<tr><td><input name='delete' type='submit' id='delete' value='Delete'></td></tr>";
$count=mysqli_num_rows($result);
if(isset($_POST['delete'])){
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id=$_POST['checkbox'][$i];
$sql = "DELETE FROM Persons WHERE id='$del_id'";
echo $sql;
$result2 = mysqli_query($con,$sql);
}
// if successful redirect to delete_multiple.php
if($result2)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_table_del.php\">";
}
}
mysqli_close($con);
echo "</table>";
echo "</form>";
?>
<br><br>
[ Back To Home ]
</body>
</html>
I am stuck, the query is not working I think. I don't know what I am missing.
Try replacing
$sql = "DELETE FROM Persons WHERE id='$del_id'";
With
$sql = "DELETE FROM Persons WHERE id=$del_id";
I'm assuming the ID is a number so the single quotes aren't needed.
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>";