I've got this query to work in the editor but now that I transfer the Code into the table code I can't seem to get it to work...
Is there something I'm doing wrong in order for this to work in the php?
Having never used the SET in a mysql query before I assume it has something to do with this, I've tried moving the SET part to separate it to no avail but not sure whether it's just something really simple that I'm missing?
<table data-role="table" id="table-column" data-theme="f" data-mode="table" class="ui-responsive table-stroke table-stripe">
<thead>
<tr>
<th style="text-align: center" data-priority="persist">Date Recorded</th>
<th style="text-align: center" data-priority="1">Max Temp C°</th>
<th style="text-align: center" data-priority="1">rH%</th>
<th style="text-align: center" data-priority="2">Hours</th>
<th style="text-align: center" data-priority="2">Hours Running Total</th>
<th style="text-align: center" data-priority="persist">pH</th>
</tr>
</thead>
<tbody>
<tr>
<?php
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($link, "SET #runtot:= 0;
SELECT q1.dated, max_temp, max_rh, q1.c, (#runtot := #runtot + q1.c) AS rt
FROM
(SELECT datestamp AS dated,
max_temp,
max_rh,
sum(hours) AS c,
ph
FROM hours
WHERE hours > 0 AND username = '$_SESSION[USERNAME]' AND batch_no = '$_SESSION[batch_no]'
GROUP BY dated
ORDER BY dated) AS q1");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysqli_num_fields($result);
for($i=0; $i<$fields_num; $i++)
{
$field = mysqli_fetch_field($result);
}
while($row = mysqli_fetch_row($result))
{
?>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[0]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[1]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[2]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[3]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[4]"?></td>
<td style="text-align: center; vertical-align: middle"><?php echo "$row[5]"?></td>
</tr>
<?php
}
mysqli_free_result($result)
?>
</tbody>
</table>
Simply changing the mysql query worked wonders.
Removing the SET.... as the first line of the code and then as the last line of the mysql, the following:
ORDER BY d) AS q1, (SELECT #runtot:=0) AS n")
Related
I'm trying to make a scrollable table with fix header. This works well if the data is entered to HTML, but when I try to echo content of my database to the table, the scroll bar messes up and my header is no longer fixed. As seen in the photo, the scroll bar is on each table entry. I've tried .div wrapping up the table body as some did but it doesn't work.
body{
background: lightblue;
}
#tble th {
text-align: left;
background-color: green;
color: white;
}
table{
display: block;
border: 1px solid;
margin-top: 10px;
width: 350px;
}
tbody{
display: block;
height: 50px;
overflow-y: scroll;
}
th {
width: 75px;
}
td {
width: 75px;
}
<html lang="en">
<body>
<table align="center" id="tble">
<thead>
<th style="text-align: center">ID</th>
<th style="text-align: center">Username</th>
<th style="text-align: center">Rights</th>
<th style="text-align: center">Age</th>
</thead>
<tbody>
<tr>
<?php
$conn = mysqli_connect("localhost", "root", "", "account");
$result = mysqli_query($conn, "SELECT * FROM account.log WHERE rights IN ('Admin','User')", MYSQLI_USE_RESULT) or die(mysql_error());
while($row = mysqli_fetch_array( $result )) {
?>
<td style="text-align: center"><?php echo $row['id']; ?></td>
<td style="text-align: center"><?php echo $row['user']; ?></td>
<td style="text-align: center"><?php echo $row['rights']; ?></td>
<td style="text-align: center"><?php echo $row['age']; ?></td>
</tr>
</tbody>
<?php
}
?>
</body>
</table>
Is there something I missed? Hoping someone could point me to the right direction.
<!-- language: lang-html -->
<html lang="en">
<body>
<table align="center" id="tble">
<thead>
<th style="text-align: center">ID</th>
<th style="text-align: center">Username</th>
<th style="text-align: center">Rights</th>
<th style="text-align: center">Age</th>
</thead>
<tbody>
<tr>//move this from here
<?php
$conn = mysqli_connect("localhost", "root", "", "account");
$result = mysqli_query($conn, "SELECT * FROM account.log WHERE rights IN ('Admin','User')", MYSQLI_USE_RESULT) or die(mysql_error());
while($row = mysqli_fetch_array( $result )) {
?>
<tr> //to here
<td style="text-align: center"><?php echo $row['id']; ?></td>
<td style="text-align: center"><?php echo $row['user']; ?></td>
<td style="text-align: center"><?php echo $row['rights']; ?></td>
<td style="text-align: center"><?php echo $row['age']; ?></td>
</tr>
</tbody>
<?php
}
?>
</body>
</table>
Sooo I've been working on a site for a friend of my dads so he can keep his business in check etc. I've been using the While Loop to print out a table of the 'Tasks' that can be inputted in to the site, however when I go to change the status of the task it's not doing so?
I'm sure that is the way I'm getting the ID for locating the record that needs to be updated, but I think I'm on the correct lines. So firstly, is there anything obvious other than my shoddy coding? Secondly, this there any better way of getting the ID or the reasoning for the lack of updating? Much Obliged!
HTML - The page
<table class="tasktable">
<tr>
<th style="text-align: center; width: 100px ">Job Number (ID)</th>
<th style="text-align: center; width: 100px">VRM</th>
<th style="text-align: center; width: 175px;">Date Arrived</th>
<th style="text-align: center;">Work</th>
<th style="text-align: center; width:200px;">Customer</th>
<th style="text-align: center; width: 250px;">Task Progress</th>
</tr>
<?php
include 'Login-System/db.php';
$query = 'SELECT * FROM outstanding WHERE taskprogress = "New" OR taskprogress = "In Progress" ORDER by id ASC';
$result = mysqli_query($conn, $query);
if($result):
if(mysqli_num_rows($result)>0):
while($tasks = mysqli_fetch_assoc($result)):
?>
<tr>
<td style="text-align: center;"><h4 name="jobnumberid"><?php echo $tasks['id'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['VRM'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['datearrived'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['work'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['customer'];?></h4></td>
<td>
<form action="SQL/taskchange.php" role="form" method="post" id="taskchange">
<select name="taskchanger" id="taskchanger" style="margin-top:6px;
width: 150px; float:left" class="form-control">
<option value="#"><?php echo $tasks['taskprogress'];?></option>
<?php
if ($tasks['taskprogress']== "New") {
echo '<option value="In Progress" class="form-control">In Progress</option>
<option value="Complete" class="form-control">Complete</option>';
} else { if ($tasks['taskprogress']== "In Progress") {
echo '<option value="New" class="form-control">New</option>
<option value="Complete" class="form-control">Complete</option>';
} else {
echo '<option value="New" class="form-control">New</option>
option value="In Progress" class="form-control">In Progress</option>';
}
}
?>
</select>
<button name="save" id="save" class="form-control" style="width: 75px; float:right;margin-top: 6px">Save</button>
</form>
</td>
</tr>
<?php
endwhile;
endif;
endif;
?>
</table>
PHP - Bit that inserts into the DB
<?php
if(isset($_POST['save'])){
include '../Login-System/db.php';
$id = mysqli_real_escape_string($conn, $_POST['jobnumberid']);
$newtask = mysqli_real_escape_string($conn, $_POST['taskchanger']);
$sql = "UPDATE outstanding SET taskprogress = '$newtask' WHERE id = '$id'";
mysqli_query($conn, $sql);
header("Location: ../outstanding.php?updated");
exit();
} else {
header("Location: ../outstanding.php?whoops");
exit();
}
Below is my code for two pages. Dashboard.php has an html table filled with 7 columns populated by my database. All are populated without any problem. In an 8th column, I have a hyperlink that says 'View'. When clicked, I want that hyper link to use the value in the serialNumber column and then when it opens up the Display.php page, I need my html tables to be filled by database values based on that serial number.
My query in display.php is meant to get the stageID from my staging table that corresponds with the serialNumber in the row where the hyperlink was clicked.
i.e., if the user hits 'View' on the row with 988809 as the serialNumber, the query should match that serial number in my staging table and select everything with that stageID and then fill my tables.
The debug statements for $_GET do echo the correct serialNumber from the line/link chosen, but on display.PHP, I only get my echo statements, no tables or data. How can I change my hyperlink or query to fix this?
Dashboard.PHP
<?php
include 'connectionDB.php';
$query1 = "SELECT * FROM staging;";
$result1 = mysqli_query($connect,$query1);
?>
<div class="dashboardTable">
<table style="border: 1px solid black;">
<tr>
<th>Work Order Packet</th>
<th>Work Order Number</th>
<th>Date</th>
<th>Utility</th>
<th>Service Name</th>
<th>Address</th>
<th>Serial No.</th>
</tr>
<?php
while($row = mysqli_fetch_array($result1)){
?>
<tr>
<td><? echo $row['workOrderPacket'];?> </td>
<td><? echo $row['workOrderNum'];?> </td>
<td><? echo $row['date'];?> </td>
<td><? echo $row['utility'];?> </td>
<td><? echo $row['serviceName'];?> </td>
<td><? echo $row['address'];?> </td>
<td><? echo $row['serialNumber'];?> </td>
<td>view</td>
</tr>
<?}?>
</table>
</div>
Display.php
<?php
if(isset($_GET['serialNumber']))
{
$query1 = "SELECT * FROM staging WHERE stageID = ".$_GET['serialNumber'].";";
$result1 = mysqli_query($connect,$query1);
while($row = mysqli_fetch_array($result1)){
?>
<div class="container">
<!--Title Line-->
<DIV class="title">
<h3>REPORT TITLE</h3>
</DIV>
<div class="TitleContainer" style="width: 100%;">
<!--Column 1 for header info-->
<DIV class="headerCol1">
<table style=" float: left; border:none;
border-collapse:collapse;">
<tr style="border: none;">
<th style="border: none; text-align: left;">Account:</th>
<th style="border: none; text-align: right;"><? echo $row['accountNum'];?> </th>
</tr>
<tr style="border: none;">
<td style="border: none; text-align: left;">Date/Time:</td>
<td style="border: none; text-align: right;"><? echo $row['date'];?>, <?echo $row['timeTested'];?> </td>
</tr>
1), use the htmlspecialcharts() method to avoid any problems of infiltration of your database -> http://php.net/manual/en/function.htmlspecialchars.php
2), If I understands well it is the condition with the ISSET which does not work well? If that's it it is strange... Try maybe with
if(!empty($_GET['serialNumber']))
{
...
I am creating a table that loops information from my database. I created the table with html and added styling via an external css sheet. The table format is not displaying in any way. None of the borders are displaying and the 100% width is not working. Could my while loop be causing this affect?
<table class="tableproduct">
<tr>
<th class="thproduct">Product ID</th>
<th class="thproduct">Product Name</th>
<th class="thproduct">Price</th>
<th class="thproduct">Category</th>
<th class="thproduct">Description</th>
</tr>
<?php
while($row = mysqli_fetch_assoc($q)) : ?>
<tr>
<td class="tdproduct"><?php echo $row['product_id']; ?> </td>
<td class="tdproduct"><?php echo $row['name']; ?> </td>
<td class="tdproduct"><?php echo $row['price']; ?> </td>
<td class="tdproduct"><?php echo $row['category']; ?> </td>
<td class="tdproduct"><?php echo $row['description']; ?> </td>
</tr>
</table>
<?php endwhile; ?>
.tableproduct {
width: 100%;
border: 1px solid black;
}
.tdproduct {
border: 1px solid black;
}
.thproduct {
height: 100px;
border: 1px solid black;
}
I ended up resolving this.
I had to put an if statement with the while loops and it created the results I was looking for.
I added this to the while loop:
if( $result ){
while($row = mysqli_fetch_assoc($result)) :
I am trying to design an HTML table where the header will stay fixed at the top of the page while scrolling down, but it is not working. Below is my html code....
<table align="center">
<?php
$select = "SELECT * FROM register where r_bid='".$_SESSION["id"]."' order by `name` ";
$result = mysql_query($select) or die(mysql_error());
$res = mysql_query("select * from regi_balic where b_id='".$_SESSION["id"]."'");
$row1=mysql_fetch_array($res);
$i=1;
echo'<thead><tr align="center">
<th width=3%><font size=3><strong>No.</strong></font></th>
<th width=10%><font size=3><strong>IC</strong></font></th>
<th width=12%><font size=3><strong>Name</strong></font></th>
<th width=12%><font size=3><strong>Reference</strong></font></th>
<th width=2%><font size=3><strong>Age</strong></font></th>
<th width=12%><font size=3><strong>Occupatin</strong></font></th>
<th width=5%><font size=3><strong>Mobile No</strong></font></th>
<th width=2%><font size=3><strong>Delete</strong></font></th>
</tr></thead>';
while($row = mysql_fetch_array($result))
{
echo '<tbody><tr>
<td width="3%" align="center" ><font size=3>'.$i.'</font></td>
<td width="10%"><font size=3>'.$row1['name'].'</font></td>
<td width="12%" align="left" ><font size=3>
<a href="edit_detail.phpid='.$row["r_id"].'
&cand_id='.$_SESSION["id"].'&email='.$row["email"].'">'.$row['name'].'</a></font></td>
<td width="12%" align="center" ><font size=3>'.$row['reference'].'</font></td>
<td width="2%" align="right" style="padding-right:8px" >
<fontsize=3>'.$row['age'].'</font></td>
<td width="12%" align="right" style="padding-right:8px"><font
size=3>'.$row['occupation'].'</font></td>
<td width="5%" align="right"><font size=3>'.$row['mob_no'].'</font></td>
<td width="2%"><a href="process_del_client.php?id='.$row['r_id'].'" onClick="return
ConfirmSubmit(\'Are You sure ?\')"><img src = "images/delete.png"></a></td>
</tr></tbody>';
$i++;
}
echo '</table></div></center>';
?>
</div>
and this is my CSS:
.list {
height: 409px;
width: 80%;
overflow: scroll;
}
Something like this? http://jsbin.com/fekoyi/1/edit
table {
height: 1000px; /* To force existence of a scrollbar. */
background: yellow; /* To aid seeing boundaries. */
}
th {
position: fixed; /* Fixes its position to the window. */
top: 0; /* Sets that fixed position to stick to the top of the window. */
width: 100%; /* Fills the width of the window; made it easier to see in your markup. */
background: pink; /* To aid seeing boundaries. */
}