Edit time in mysql output - php

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.

Related

PHP show odbc_fetch_row for 50 records then show X+50

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.

search database with php POST and mysql_fetch_ array

I'm trying to create a search form to search through my mysql database.
I succeded to to create the form with one text field and a submit buttom. BUT..
When I leave the text field blank and hit the submit button all results appear from the specific database table on my search.php site.
When i write anything in the text field (text that is included in the names from the database) and hit the submit button no search results appear at all.
As you can see in the code I've been trying to list the search results in two diferent ways. The first one reacts as described above. The last one does not list any search results at all.
Do anybody know why? Do I have a typo somewhere or do I miss anything ind the code?
Thanks in advance.
This is my index.php
<! DOCTYPE html>
<html>
<head>
<meta charset ="UTF-8">
<title> Townin </title>
<link rel="stylesheet" type="text/css" href="Townin/style.css">
<style>
body {background-color: white;}
header{background-color:#6ab47b;
border-color:#599a68;
}
header h1, h2 {margin-left: 20px;
color: white;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
h1, h1 {margin-left: 20px;
color: gray;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
p {margin-left: 20px;
color: gray;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
nav a, nav a:visited {
color: white;
background-color: #599a68;}
nav a.selected, nav a:hover{color: black;
background-color:#6ab47b;}
nav {
text-align:center;
padding: 0 0;
margin:20px 0 0;
height: 50 px;
background-color:#599a68;
}
nav ul {
list-style:none;
margin: 0px 10px;
padding: 0px;
}
nav ul li {
display: inline-block;
border-right: 1px solid #6ab47b;
text-align: center;
width: 250px;
padding:0px 0px;
}
nav ul li a {
display: block;
height: 40px;
width: 100%;
line-height:50px;
background-color: #599a68;
}
li a:hover {
background-color: #6ab47b;
}
a:link {
text-decoration: none;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color:gray;
}
a:visited {
color:gray;
}
.button {
background-color:#6ab47b;
color: #fff;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
margin: 0px 20px;
padding:20px 20px;
border-radius: 100 %;
}
.button:visited {
color:white;
}
#bar-knap {
display: inline-block;
max-width: 100%;
border-radius:10%;
height:40%;
width:20%;
margin: 10px 10% 10px 10%;
border-style:solid;
border-color:gray;
}
#spise-knap {
display: inline-block;
max-width: 100%;
border-radius:10%;
height:40%;
width:20%;
margin:10px 10% 10px 10%;
border-style:solid;
border-color:gray;
}
footer {
background-color: #6ab47b;
color: white;
height: 70px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: center;
margin: 20px auto 0px auto;
}
</style>
</head>
<body>
<?php include ("Header2.php"); ?>
<a href="barer.php" >Barer
<img src="img/barknap.jpg" alt="Barer" id="bar-knap">
</a>
<a href="spisesteder.php" >Spisesteder
<img src="img/spiseknap.png" alt="Spisesteder" id="spise-knap">
</a>
<!--Search form-->
<p style="text-align:center;"> Søg mellem barer </p>
<br />
<br />
<form method="post" action="search.php">
<input type="text" name="search" />
<input type="submit" name="submit" value=" Search ">
</form>
<br />
<br />
<footer>
Natalie
</footer>
</body>
</html>
And this is the search.php
<?php
//Connection to phpmyadmin
//Step1
$db = mysql_connect("host","username","password");
if (!$db) {
die("Database connection failed miserably: " . mysql_error());
}
//Step2
$db_select = mysql_select_db("databasename",$db);
if (!$db_select) {
die("Database selection also failed miserably: " . mysql_error());
}
$search = $_POST[search];
//SQL statement to select what to search
$sql="SELECT * FROM Brugerdatabase
WHERE 'Navn' like '%$search%' OR
'Mad genre' like '%$search%' OR
'Beliggenhed' like '%$search%'
ORDER BY Navn ASC";
// Run sql statement
$result = mysql_query($sql, $db) or die(mysql_error());
//Find out how many matches
$number= mysql_num_rows($result);
$pagetitle ="Search Results";
?>
<!doctype html>
<html lang="da">
<head>
<meta charset ="UTF-8">
<title>Søge resultater</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
table {
border-collapse: collapse;
width: 80%;
margin:0 5%;
}
table th, td {
border-bottom:1px solid gray;
height: 50px;
vertical-align: center;
padding: 15px;
text-align: left;
}
tr:hover{background-color:#f5f5f5}
fieldset {
width: 60%;
margin:0 20%;
box-align: center;
}
</style>
</head>
<body>
<?php include ("Header2.php"); ?>
<!--Advanceret søge funktion-->
<p style="text-align:center;"> Søge resultater</p>
<?php
//------------------------------------
//This code inside the lines list the results when nothing is typed in the search field.
//Creates a loop to loop through results
while($row = mysql_fetch_array($result)){
echo "<table><tr><td>"
. $row['1'] .
"</td><td>"
. $row['4'] .
"</td><td>"
. $row['5'] .
"</td><td>"
. $row['6'] .
"</td><td>"
. $row['7'] .
"</td><td>"
. $row['8'] .
"</td></tr></table>";
}
//-----------------------------------
//-------------------------------
//This code inside the lines does not list anything at all..
// loop through results and get variables
while ($row=mysql_fetch_array($result)){
$navn =$row["Navn"];
$genre =$row["Mad genre"];
$beliggenhed =$row["Beliggenhed"];
}
// Tabel with search results
print " <tr>
<td>
<form method=\"post\" action=\"confirmdelete.php\">
<input type=\"hidden\" name=\"sel_record\" value=\"$id\">
<input type=\"submit\" name=\"delete\" value=\" Delete \">
<form>
<form method=\"post\" action=\"updateform.php\">
<input type=\"hidden\" name=\"sel_record\" value=\"$id\">
<input type=\"submit\" name=\"update\" value=\" Edit \">
</form>
</td>
<td><strong>$navn</strong><br />
Mad genre: $genre<br />
Beliggenhed: $beliggenhed</td>
</tr>";
print "</tr></table></body></html>";
//----------------------------
mysqli_close($db);
?>
</body>
</html>
You need to encase your array keys -in this example with single quotes- so:
$search = $_POST['search'];
You should also real_escape string your key with:
$search = mysql_real_escape_string($_POST[search]);
...As a minimum (read below)
Your search SQL you should not encase your column names, so rewrite them as:
$sql="SELECT * FROM Brugerdatabase
WHERE Navn like '%$search%' OR
`Mad genre` like '%$search%' OR
Beliggenhed like '%$search%'
ORDER BY Navn ASC";
You SHOULD encase the middle column within backticks (`) because the column name contains a space. quotes should only go around values, not column or table names.
Now, read again the line LIKE '%$search%' OR ... if $search is empty then this will return a string of <anyvalue><null><anyvalue> ==> %%, so this will return any of the columns that are not NULL because they contain something.
Your code detailed below does not output anything to the browser to display so you will never have anything to show for your query:
//This code inside the lines does not list anything at all..
// loop through results and get variables
while ($row=mysql_fetch_array($result)){
$navn =$row["Navn"];
$genre =$row["Mad genre"];
$beliggenhed =$row["Beliggenhed"];
}
Finally, you really, REALLY should be looking into using MySQLi rather than the standard MySQL as that has been Deprecated and removed from current/future versions of PHP. It's use is really not a good idea and it's riddled with flaws and holes.

Design php output table with css

Please anyone who can help me with this problem. I have a html file with a question. When submit is clicked it calls a php(which is connected with my database in Oracle) and it shows a table inside the html (using ajax).
I would like to know how can i show that table in a nicer form? Can I design it?
Here is my code in php
<?php
{
session_start();
include "connect.php";
}
$conn = DBConnect();
$stid = DBExecute($conn, "select something...");
$total = 0;
echo "<table>
<tr>
<th>Name1</th>
<th>Name2</th>
</tr>";
while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
echo "<tr><td>";
echo $row['something'];
echo "</td>";
echo "<td>";
echo $row['something'];
echo "</td>";
}
echo "</table>";
?>
and I want to have for example this css instructions for the table i will show...
#newspaper-a
{
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
margin: 45px;
width: 480px;
text-align: left;
border-collapse: collapse;
border: 1px solid #69c;
}
#newspaper-a th
{
padding: 12px 17px 12px 17px;
font-weight: normal;
font-size: 14px;
color: #039;
border-bottom: 1px dashed #69c;
}
#newspaper-a td
{
padding: 7px 17px 7px 17px;
color: #669;
}
#newspaper-a tbody tr:hover td
{
color: #339;
background: #d0dafd;
}
Please does anyone know what should i do to succeed it???
Important the table will be shown inside the same page not in another one..
You need to add your ID to the table div - like this:
<?php
{
session_start();
include "connect.php";
}
$conn = DBConnect();
$stid = DBExecute($conn, "select something...");
$total = 0;
// ADD YOUR ID HERE vvvvvvvv
echo "<table id="newspaper-a">
<tr>
<th>Name1</th>
<th>Name2</th>
</tr>";
while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
echo "<tr><td>";
echo $row['something'];
echo "</td>";
echo "<td>";
echo $row['something'];
echo "</td>";
}
echo "</table>";
?>
http://jsfiddle.net/jakemulley/hs3mF/

CSS white-space: nowrap not working in IE

Having a problem in IE with CSS nowrap in IE, works perfectly in Chrome. Can anyone help out so it renders without any wrapping in IE and Chrome?
HTML
<div id="sub_cont"></div>
CSS
#content{
height:14px;
text-align: left;
text-decoration: none;
width: 450px;
padding-top:25px;
white-space: nowrap;
}
#content #sub_cont{
width: 450px;
display:none;
height:14px;
}
#content .no-rec{
color:#000;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
padding:5px;
border-bottom:solid #000;
text-align:left;
background:#EBEBEB;
}
#content .each_rec {
background: none repeat scroll 0 0 #EBEBEB;
border-bottom: medium solid #000000;
color: #000;
font-family: Arial,Helvetica,sans-serif;
font-size: 14px;
padding: 5px;
height:12px;
}
PHP
<?php
echo "<h2>Search Result</h2>";
echo "<table border='0' id='content' cellspacing='2' cellpadding='5'>
<tr bgcolor='#FFFFCC'>
<th>VM Name</th>
<th>vCenter Name</th>
</tr>";
while ($row = sqlsrv_fetch_array($result))
{
echo "<tr class='each_rec'>";
echo "<td>" . $row['VM_NAME'] . "</td>";
echo "<td>" . $row['VCENTER_NAME'] . "</td>";
echo "</tr>";
}
echo "</table>";
if($total==0){ echo '<div class="no-rec">No Record Found !</div>';}?>
In internet explorer we must use the whiteSpace property in order to nowrap text, the documentation for the usage of whiteSpace is linked below. Good luck, and remember to use the most recent version of IE in order to maintain accuracy.
Link: http://msdn.microsoft.com/en-us/library/ie/ms531182(v=vs.85).aspx
Reference url
https://stackoverflow.com/a/18129006/1312610
http://css-tricks.com/almanac/properties/w/whitespace/
Try it for ie
white-space: normal;

Coloring the table with alternate color

Below i have added my css file and my html file i need to color my table with alter name color but its not working i don't know where i have done the mistake.
CSS FILE :-
table.gridtable{
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
float:center;
border-width:1px;
border-style:groove;
border-color:black;
border-collapse:collapse;
width:600px;
}
table.gridtable th{
border-width:1px;
padding:3px;
border-style:solid;
border-color:black;
}
table.gridtable td{
border-width:1px;
padding:3px;
border-style:solid;
border-color:black;
}
.oddrowcolor{
background-color: black;
}
.evenrowcolor{
background-color: red;
}
table.gridtable td.darkcol{
border-top:0px;
border-bottom:0px;
border-right: 1px;
}
table.gridtable td.emptycol{
border-bottom:0px;
border-right: 1px;
}
HTML & PHP:-
<table class="gridtable" id="alternatecolor" align="center"
<tr><th>disease Name/th><th>Gene Name/th><th>OMIM Number</th></tr>
<?php
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("missensencemuttation",$dbhandle) or die("Could not select disease");
$result = mysql_query("SELECT DISTINCT * FROM `gene_data` ORDER BY disease_name");
$last=" ";
while($row = mysql_fetch_array($result))
$now=$row[2];
if($last != $now){
$rcnt=mysql_query("select count(gene_name) from gene_data where gene_name='$now'");
if($rcnt==1){
echo "<tr><td>";
echo "<a href='d1.php?d_name=".$row['disease_name']."'>".$row['disease_name'];
echo "</a></td>";
echo "<td>".$row['gene_name']."</td>";
echo "<td>".$row['ommi_number']."</td></tr>";
}
else{
echo "<tr><td class='emptycol'>";
echo "<a href='d1.php?d_name=".$row['disease_name']."'>".$row['disease_name'];
echo "</a></td>";
echo "<td>".$row['gene_name']."</td>";
echo "<td>".$row['ommi_number']."</td></tr>";
}
}
else
{
echo "<tr'>";
echo "<td class='darkcol'>";
echo '&nbsp';
echo "</td>";
echo "<td>".$row['gene_name']."</td>";
echo "<td>".$row['ommi_number']."</td></tr>";
}
$last=$row[2];
can any one help me with this ??
Maybe I'm misunderstanding, but it looks like you want to apply oddrowcolor or evenrowcolor to alternating rows - but in your actual php/html, I don't see those class names anywhere. They're not being put on the rows, so their rules wont be applied. Just add them to the appropriate <tr> tags in your php and it should work.
Alternatively you could use the nth-of-type selector to apply the rules without altering your php:
tr:nth-of-type(odd) {
background-color: black;
}
tr:nth-of-type(even) {
background-color: red;
}
If you want alternate colors for each table row, then a simple CSS should do it. This way, if you want to insert new rows dynamically, it will adjust the colors automatically.
.stripped-rows:nth-child(odd){
background-color:red;
}
.stripped-rows:nth-child(even){
background-color:blue;
}
and html ...
<table>
<tr class = 'stripped-rows'>
<td>sad</td>
</tr>
<tr class = 'stripped-rows'>
<td>sad</td>
</tr>
<tr class = 'stripped-rows'>
<td>sad</td>
</tr>
DEMO

Categories