Okay I tried this before and it got closed because it wasn't specific. Below is my entire page code. Please ignore the font and html stuff because all of that is working fine. My Specific question is how to alter this so that the column called "Given" is reset to 0 (zero) at the first day of each month automatically. I am only specifically asking for how to make this happen.
Everything else is working to manually add and subtract, etc. I only need assistance in making that column reset to zero on the first day of each month.
TO BE EVEN MORE SPECIFIC the column "OWED" in the database should be reset to 0 (zero) at the first day of each month automatically to achieve this.
I am new to coding and this code was made for me months ago, and while I have learned a lot since then, I do not seem to find any example to learn from on how to make what I am asking happen. Thank you
EDIT - The objective is to reset all of the rows in the "Owed" column at the same time. Either automatically each month, or manually with one button (or image button)
<?php
$servername = "localhost";
$username = " ";
$password = " ";
$db=" ";
$conn = mysqli_connect($servername, $username, $password,$db);
// $sql = "INSERT INTO `number`( `number`)
// VALUES ('$qty')";
$sql = "SELECT id,name,requests,owed FROM record ORDER BY name";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<style>
table#customers {
width: fit-content;
margin: auto;
margin-top: 2px;
}
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
border: 2px solid #B7B7B7;
padding: 4px;
}
#customers tr:nth-child(even){background-color: #ffffff;}
#customers tr:nth-child(odd){background-color: #f2f2f2;}
#customers tr:hover {background-color: aliceblue;}
#customers th {
padding-top: 2px;
padding-bottom: 2px;
text-align: center;
background-color: #FFB951;
color: black;
}
.sub-add{
float: right;
}
span.sub-add a {
text-decoration: none;
margin: 1px;
}
</style>
</head>
<body leftmargin="0" topmargin="0">
<meta http-equiv="refresh" content="10" >
<table id="customers" bgcolor="#CCCCCC">
<tr>
<th height="5" width="20%">Name</th>
<th height="5" width="20%" style="display:none">Requests</th>
<th height="5" width="10%">Earned</th>
<th height="5" width="10%">Given</th>
<th height="5" width="10%">Owed</th>
</tr>
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$earned = $row["requests"]/1;
$owed = $row["owed"];
$earned = (int)$earned;
$owedtoo = $earned - $owed;
echo '<tr><td><center><b><font color="Orange">'.$row["name"].'<font></b><br><a onclick="return confirm(\'Are You SURE You Want To Delete?\')" href="delete.php?id='.$row['id'].'">Delete</a> | Edit
</center></td><center><td style="display:none"><center>'.$row["requests"].'<span class="sub-add"><span>-</span> <span> +  </center></span></span></td></center><td><center><b><font color="green">'.$earned.'</font></b></td><center><td><center><b>'.$row["owed"].'</b><span class="sub-add"><span> - </span> <span> + </span></span></center></td><td><center><b><font color="red">'.$owedtoo.'</font></b></td></tr>';
}
}
?>
</table>
</body>
</html>
<?php $conn->close(); ?>
Use cron jobs for routine or date/time specific tasks.
Good question thread here: How to create cron job using PHP?
Related
I am trying to put in a search filter that makes it so you can enter the lock number and it will return just the fields from the phpmyadmin database that has that lock number associated with it. The file name is dataout.php.
<?php
$db_host = 'localhost';
$db_user = 'nick';
$db_pass = 'ramon';
$db_name = 'lockout'; ?>
<link href="lockproject.css" type="text/css" rel="stylesheet">
<input type="text" name="locknumber" placeholder="Enter Lock Number"><br>
<br>
<input type="submit" name="search" value="Submit">
<?php
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Fail to connect to MySQL: ' . mysqli_connect_error());
}
$sql = 'SELECT ID, lock_number, equipment_number, work_order, date_out,
supervisor_out, comments_out, date_in, supervisor_in
FROM form';
$query = mysqli_query($conn, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
echo '<table width="60%" align="center">
<thead>
<tr>
<th>ID</th>
<th>Lock Number:</th>
<th>Equipment</th>
<th>Work Order:</th>
<th>Date OUT:</th>
<th>Supervisor Initial OUT:</th>
<th>Comments/Tradesmen:</th>
<th>Date In:</th>
<th>Supervisor Initial in:</th>
</tr>
</thead>
<tbody>';
while ($row = mysqli_fetch_array($query))
{
echo '<tr>
<td>'.$row['ID'].'</td>
<td>'.$row['lock_number'].'</td>
<td>'.$row['equipment_number'].'</td>
<td>'.$row['work_order'].'</td>
<td>'.$row['date_out'].'</td>
<td>'.$row['supervisor_out'].'</td>
<td>'.$row['comments_out'].'</td>
<td>'.$row['date_in'].'</td>
<td>'.$row['supervisor_in'].'</td>
</tr>';
}
echo '
</tbody>
</table>';
mysqli_free_result($query);
mysqli_close($conn);
?>
<a href="http://152.116.203.115/lockcheckin2.php" target='_blank'>Lock
Check
In Form</a>
<a href= "http://152.116.203.115/lockcheckoutbeta.php"
target='_blank'>Lock
Check Out Form</a>
Here is the code for the css file that is attached to it called lockproject.css
{
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
h1 {
border-bottom: 2px solid rgba(255, 255, 255, 0.5);
color: white;
font-weight: 120;
font-size: 36px;
line-height: 30px;
padding-bottom: 20px;
text-align: center;
width: 100%;
}
h3 {
color: #F81B1D
}
td, th {
border: 2px solid #ddd;
padding: 14px;
}
tr:nth-child(odd){background-color: #f2f2f2;}
tr:nth-child(even){background-color: #214CD2;}
th {
padding-top: 14px;
padding-bottom: 14px;
text-align: left;
background-color: #000000;
color: white;
}
body {
background-color: #4D4949;
}
a:link, a:visited {
background-color: #214CD2;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: blue;
}
This can be solved by using a SQL where statement, a good example is shown here: https://www.w3schools.com/sql/sql_where.asp
By using a GET request in the HTML form, we can get the value from the field and use it in out PHP script. See:
https://www.w3schools.com/php/php_forms.asp
Html file:
This will submit the lock number to the file as a get request
<form action="dataout.php" method="get">
Name: <input type="text" name="lock_number"><br>
<input type="submit">
</form>
</body>
</html>
PHP script:
We get the value associated with the GET request and use it in the query
For protection you should use prepared statements.
http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
$sql = "SELECT ID, lock_number, equipment_number, work_order, date_out, supervisor_out, comments_out, date_in, supervisor_in FROM form WHERE lock_number = ?";
$stmt = $this->conn->prepare($sql);
$stmt->bind_param('s', $lock_number);
$stmt->execute();
$stmt->bind_result($result);
while ($stmt->fetch()) {
//This while give back a row at a time.
//This contains only the rows that the WHERE statement gets
}
Edited in light of Patrick Q's and Sam Swift's comments.
What you do is SELECT from the TABLE where the lock number in the table equals the entered input. That's all. Nothing hard about it. Also don't use the die function it's deprecated.
What you're looking for is:
if(isset($_POST['submit'])) {
$lock_number = $_POST['lock_number'];
$sql = 'SELECT id, lock_number, equipment_number, work_order, date_out,
supervisor_out, comments_out, date_in, supervisor_in
FROM form WHERE lock_number = "{$lock_number}",'
}
First you check if the button has peen pressed then put the entered input into a variable then query the database based on it. It will return the wanted row.
You need to do 2 thing:
Put search box in a form tag, submit button should come under form tag.
<form id="search-form" method='POST'>
<input type="text" name="locknumber" placeholder="Enter Lock Number"><br>
<br>
<input type="submit" name="search" value="Submit">
</form>
Now Need to update $sql Query with condition. after $sql query, need to check if lockumber value is coming in post and not empty we have to add condition with query as given below.
$sql = 'SELECT ID, lock_number, equipment_number, work_order, date_out,
supervisor_out, comments_out, date_in, supervisor_in
FROM form';
if (isset($_POST['locknumber']) && !empty($_POST['locknumber'])) {
$sql .= " where lock_number = '" . $_POST['locknumber'] . "'";
}
Hopefully this can help you to resolve your issue. Thanks.
I dabble in php, and I am doing some display screens for our office. Mainly SQL (some MSSQL and now DB2) selections that are formatted and shown on a 40" monitor in portrait.
I do have a problem, hence the question :)
I can comfortably show 50 records on a screen. Unfortunately the records can vary from 1 to 300 during the day (order/shipping data).
I am looking for a dynamic way of showing the first 50 records for 30 seconds, then the next 50 for 30 seconds etc... then at the end of the loop refresh the page to pull the new data-set and start from 1.
Basic script that I have (unformatted) is as follows:
<!DOCTYPE html>
<html>
<head>
<meta content="en" http-equiv="Content-Language">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Shipping</title>
<style type="text/css">
.auto-style1 {
border-left: 1px solid #C0C0C0;
border-right-style: solid;
border-right-width: 1px;
border-top: 1px solid #C0C0C0;
border-bottom-style: solid;
border-bottom-width: 1px;
text-align: center;
}
.auto-style2 {
border-left-style: solid;
border-left-width: 1px;
border-right: 1px solid #C0C0C0;
border-top-style: solid;
border-top-width: 1px;
border-bottom: 1px solid #C0C0C0;
text-align: center;
}
</style>
</head>
<?php
$server="Driver={Client Access ODBC Driver (32-bit)};System=server";
$user="username"; #a valid username that will connect to the DB
$pass="password"; #a password for the username
$conn=odbc_connect($server,$user,$pass); #you may have to remove quotes
#Check Connection
if ($conn == false) {
echo "Not able to connect to database...<br>";
}
#Query the Database into a result set -
$result=odbc_exec($conn,"
select * from table");
if (!$result)
{exit("Error in SQL");}
echo "<table class='auto-style2' style='width: 800px'><tr><td class='auto-style1'>Shipment Number</td><td class='auto-style1'>Shipment Date</td><td class='auto-style1'>End customer order number</td><td class='auto-style1'>Qty</td></tr>";
while (odbc_fetch_row($result))
{
$b=odbc_result($result,1);
$c=odbc_result($result,2);
$d=odbc_result($result,3);
$e=odbc_result($result,4);
echo " <tr><td class='auto-style1'>$b</td>";
echo " <td class='auto-style1'>$c</td>";
echo " <td class='auto-style1'>$d</td>";
echo " <td class='auto-style1'>$e</td></tr>";
}
echo "</table>";
#close the connection
odbc_close($conn);
?>
Any help will be greatly appreciated.
Have a question, I found this:
http://www.phpdevtips.com/2013/06/email-open-tracking-with-php-and-mysql/
So was able to get it working and even figured out how to show the data in a page, this one:
<html>
<head>
<meta http-equiv="refresh" content="900">
<title>Who read his e-Mail, and when?</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<style>
* {
box-sizing: border-box;
}
.txt {
font-family: 'Open Sans', sans-serif;
font-size: 11px;
text-align: left;
}
h2 {
padding: 5px;
font-family: 'Open Sans', sans-serif;
font-size: 24px;
text-align: left;
font-weight: bold;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 12px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2>Who read his e-Mail, and when?</h2>
<?php
mysql_connect("localhost", "***", "***") or die (mysql_error ());
mysql_select_db("***") or die(mysql_error());
$strSQL = "SELECT * FROM email_log";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo "<table border='1' width='100%' style='border-collapse: collapse' cellpadding='5' class='txt' id='myTable'>";
echo "<tr class='header'>";
echo "<td width='5%' class='txt'>";
echo $row['id'] . "</td><td width='30%' class='txt'>";
echo $row['user'] . "</td><td width='40%' class='txt'>";
echo $row['subject'] . "</td><td width='25%' class='txt'>";
echo $row['opened'] . "</td>";
echo "</tr>";
echo "</table>";
}
mysql_close();
?>
</body>
</html>
So far, so good, now my question is, the date and time that get´s pulled out of the database in the row opened is showing like this on the result page: 2017-03-09 07:53:58
I would like it to show as 07:53:58 09-03-2017
and it should be 6 hours later, as this seems to me that what it is showing now is server time, not our timezone.
So reaching out for your help, anyone can give me a push into the right direction? Any Help appreciated.
Joris
For changing the date format you can use
date('h:i:s d-m-Y', strtotime($row['opened']));
The best way to manage the time zone, you can set a timezone, at the place where you are inserting the date time to database. Initialise the timezone what you want before mapping to database.
date_default_timezone_set("Asia/Bangkok");
instead of "Asia/Bangkok" you can give your timezone
Thank you all, great solutions, this one did it best:
echo date('H:i:s d-m-Y', strtotime($row['opened'])+21600);
Tnx, Greetz from Spain :)
SELECT DATE_FORMAT(opened,'%H:%i:%s %d-%m-%Y')opened,id,user,subject FROM email_log
You can try DATE_FORMAT()of MySQL.
Try above code hope this will helps.
Need some help.
I'm creating a table view with grid/borders.
However,some borders can't be seen although I'm including in tags the style=''.
Much better if I will tell that I only see the table border which is included in table tag.
Please see attached file for the format.
By the way I'm getting the records in database via PHP script.
Here is my code:
$result.="<br/><br/><br/>
<table style='border:solid 1px;'>";
$result.="<thead style='border-bottom:thin solid'><th style='text- align:center;border-style:solid 1px'>YC ".$store_name."</th></thead>
<tr><td></td>
<td colspan='3'>Service Time </td>
<td colspan='3'>Production Time</td>
<!--<td colspan='3'>Customer Feedback</td>
<td colspan='3'>Customer Feedback</td>
<td colspan='3'>Customer Feedback</td>-->
</tr>
<tr></tr>
<tr>
<td></td>
<td>TC Within<br>30 mins.</td>
<td>Total<br>TC</td>
<td><br/>%</td>
<td>Within 15 <br/>mins.</td>
<td>Total <br/>TC</td>
<td><br/>%</td>
</tr>
<tr></tr>";
//get PartView
$query = "SELECT * FROM Part_view WHERE StoreID = ".$store_id." AND datepart(month,TransDate) = '".$month."' AND datepart(year,TransDate) = '".$year."' ORDER BY TransDate ASC ";
$que = mssql_query($query);
while($row=mssql_fetch_array($que)){
$transdate =date('d',strtotime($row['TransDate']));
$tc30 = $row['TC30'];
$totaltc30 = $row['Total_TRX1'];
$hitrate = round($row['Hitrate']);
$pd15 = $row['PDT15'];
$totalpd15 = $row['Total_TRX2'];
$production = round($row['ProdTime']);
$excellence = $row['Excellence'];
$totalexcellence = $row['Total_TRX4'];
$excellencepercent = round($row['ExcelPercent']);
$good = $row['Good'];
$totalgood = $row['Total_TRX5'];
$goodpercent = round($row['GoodPercent']);
$poor = $row['Poor'];
$totalpoor = $row['Total_TRX6'];
$poorpercent = round($row['PoorPercent']);
if($hitrate==""){
$hitrates = "";
}else{
$hitrates = $hitrate;
}
$result.="<tr>
<td>".$transdate."</td>
<td>".$tc30."</td>
<td>".$totaltc30."</td>
<td>".$hitrate."% </td>
<td>".$pd15."</td>
<td>".$totalpd15."</td>
<td>".$production."% </td>
</tr>";
}
$result.="</table>";
echo $result;
Can someone help me?
OK, I think what you are actually asking is why the entire grid isn't being 'bordered'. You can use CSS to accomplish this far cleaner than inline styles. You need to set styles for TD.
Code:
table {
border-width: 1px;
border-spacing: 0px;
border-style: solid;
border-color: black;
border-collapse: separate;
background-color: white;
}
table th {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: black;
background-color: white;
}
table td {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: black;
background-color: white;
}
If you use this in your CSS you can remove all the inline styling you have already, this code will fix it all.
You can use this tool to create the table. But I recommend you to do that by yourself. And you should include your code and we can help you to fix that.
Tool: http://divtable.com/generator/
So I've been working on a small system which involves codes which is used for a user to redeem them for some sort of reward.
So far I have this script in PHP and HTML:
http://pastebin.com/UUsEKpev
It's only showing one result which you can see here, I want it to display multiple results in a table going down showing all results.
<?php
$yn;
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("mcv") or die(mysql_error());
$result = mysql_query("SELECT * FROM Codes")
or die(mysql_error());
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
if ($row['Used'] == 1) {
$yn = "Yes";
}
else{
$yn = "No";
}
?>
<html>
<head>
<title>Minecraft Codes</title>
<style type="text/css">
tbody {
display: table-row-group;
vertical-align: middle;
border-color: inherit;
}
tr {
display: table-row;
vertical-align: inherit;
border-color: inherit;
}
th {
border: 1px solid #C3C3C3;
padding: 3px;
vertical-align: top;
width: 20%;
background-color: #E5EECC;
}
table.reference {
background-color: white;
border: 1px solid #C3C3C3;
border-collapse: collapse;
width: 50%;
}
table.reference td {
border: 1px solid #C3C3C3;
padding: 3px;
vertical-align: top;
width: 20%;
}
table, th, td, input, textarea {
font-size: 100%;
}
body, p, h1, h2, h3, h4, table, td, th, ul, ol, textarea, input {
font-family: verdana,helvetica,arial,sans-serif;
}
</style>
</head>
<body>
<center>
<br />
<h1><u>Minecraft Server VIP Codes</u></h1>
<br />
<table class="reference">
<tr>
<th>Code</th>
<th>Used?</th>
</tr>
<?php echo "<tr><td>".$row['Code']."</td><td>".$yn."</td></tr>"; ?>
</table>
</center>
</body>
</html>
Your problem is that you are only fetching one row:
$row = mysql_fetch_array( $result );
That line fetches the current row of the result set. You want to do that in a loop:
$rows = array();
while ($row = mysql_fetch_array($result)) {
$rows[] = $row;
}
If you can please avoid using the mysql_ functions, they are deprecated, see the giant warning here and read this
<table class="reference">
<tr>
<th>Code</th>
<th>Used?</th>
</tr>
<?php while ($row = mysql_fetch_array($result)): ?>
<?php
if ($row['Used'] == 1) {
$yn = "Yes";
}
else{
$yn = "No";
}
?>
<tr>
<td><?php echo $row['Code']; ?></td>
<td><?php echo $yn; ?></td>
</tr>
<?php endwhile; ?>
</table>
Well yes, you call mysql_fetch_row() only a single time, thus you only retrieve a single row. You have to wrap that into a loop that is executed as many times as there are rows.
There are millions of examples on the internet that you can learn from...