Design php output table with css - php

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/

Related

Edit time in mysql output

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 to put color to a html table through css

<?php
$con=mysqli_connect("localhost","root","","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$co_name = mysqli_real_escape_string($con, $_POST['co_name']);
$co_address = mysqli_real_escape_string($con, $_POST['co_address']);
$co_website = mysqli_real_escape_string($con, $_POST['co_website']);
$co_phoneno = mysqli_real_escape_string($con, $_POST['co_phoneno']);
$co_contactperson = mysqli_real_escape_string($con, $_POST['co_contactperson']);
$therapist_id = mysqli_real_escape_string($con, $_POST['therapist_id']);
$result = mysqli_query($con,"SELECT * FROM therapist_office WHERE therapist_id='".$user_id."'");
echo"<table id='miyazaki' style='border-collapse: collapse; border: 1px solid; margin-left:180px; width:1000px; margin-top:30px;'>";
echo"<thead style='border:1px solid; background-color:#ffe3ab;' >";
echo"<tr>";
echo"<th style='border: 1px solid; padding: .65em;' >Office Name</th>";
echo"<th style='border: 1px solid; padding: .65em;' >Address</th>";
echo"<th style='border: 1px solid; padding: .65em;' >Website</th>";
echo"<th style='border: 1px solid; padding: .65em;' >PhoneNo</th>";
echo"<th style='border: 1px solid; padding: .65em;'>Contact Person</th>";
echo"</tr>";
echo"</thead>";
while($row = mysqli_fetch_array($result))
{
echo"<tbody>";
echo"<tr>";
echo "<td style=' padding: .65em;'>" . $row['co_name'] . "</td>";
echo "<td style=' padding: .65em;'>" . $row['co_address'] . "</td>";
echo "<td style=' padding: .65em;'>" . $row['co_website'] . "</td>";
echo "<td style=' padding: .65em;'>" . $row['co_phoneno'] . "</td>";
echo "<td style=' padding: .65em;'>" . $row['co_contactperson'] . "</td>";
echo"</tr>";
echo"</tbody>";
}
echo"</table>";
mysqli_close($con);
?>
I have this table that is simple but i am not able to add colors through css to it, at present i have used inline css will convert it to external css later. i wish to show the table head with different color and the rows of the table that contain data should be of 2 colors that run alternatively. Would appreciate if someone could help me
P.S some people wanted to see my other sheet, here it is
<style>
table { border-collapse: collapse; font-family: Futura, Arial, sans-serif; border: 1px solid ; margin-left:180px; width:1000px; margin-top:30px;}
caption { font-size: larger; margin: 1em auto; }
th, td { padding: .65em; }
th, thead { background-color: ffecc4; border: 1px solid ; }
tr:nth-child(odd) { background: #ccc; }
tr:hover { background: #aaa; }
td { border-right: 1px solid #777; }
</style>
In html TABLE you cannot give background-color or color to <thead>. <thead> doesn't not take any colors. You can do..
#miyazaki thead th{
background-color:red;
color:#000;}
And for alternate colors you can apply
#miyazaki tr:nth-child(odd){
background: #b8d1f3;
}
#miyazaki tr:nth-child(even){
background: #dae5f4;
}
Do it with jquery:
<script>
$(document).ready(function() {
$("#miyazaki tr:even").css("background-color", "#CCC");
$("#miyazaki tr:odd").css("background-color", "#FFF");
});
</script>
You can do it with CSS:
#miyazaki tr:nth-child(even) {background: #CCC}
#miyazaki tr:nth-child(odd) {background: #FFF}
Reference
Note: No support in IE 8 for this.
Or, if you have jQuery:
<script>
$(document).ready(function() {
$("#miyazaki tr:even").css("background-color", "#CCC");
$("#miyazaki tr:odd").css("background-color", "#FFF");
});
</script>
if you add classes to you code e.g
`echo"<th style='border: 1px solid; padding: .65em;' class='tblHead'>Office Name</th>";`
and
`echo "<td style=' padding: .65em;'>" . $row['co_name'] . " class='tblRow' </td>";`
Then you can write some CSS to set styles for those classes.
like:
.tblHead {
background-color: yellow;
}
.tblRow{
background-color: green;
}

Dropdown menu wont stick to table

I have a CSS related problem, that would look easy, but I have been slamming my head against the wall for the last hour, since the tweaks arround i tried are not applying.
For some odd reason, the select dropdown menu wont stick into the cell, but is placed above the table.See picture below
The loop code to generate the table is build up as followed: (i didnt bother posting the php cause thats not relevant)
echo '<tr class="items">';
echo '<td id="cell11">'.$Date.'</td>';
echo '<td id="cell21">'.$link.'</td>';
echo '<td id="Fright1">'.MakeUserRoleDropdown($StatusId).'</td>';
echo '</tr>';
The CSS is pretty basic:
select { width: 367px; font-family: Verdana; font-size: 12px; color: #666; background: white; border: 1px solid #CECECE; padding: 4px;}
.dropdownrole { width:150px;}
#cell11 { padding-left: 10px; padding-right: 10px; width: 200px; text-align:left;}
#cell21 { padding-left: 10px; padding-right: 10px; width: 200px; text-align:left;}
#Fright1 { padding-left: 10px; padding-right: 10px; width: 200px; text-align:right;}
table.items tr { height: 32px; background:url(../images/tableRow.png); border-top: 1px solid #CCC; padding: 0; margin: 0;}
.items { width: 100%; border-collapse: collapse; color: ##797979; font-family: Verdana; font-size: 11px; }
table { border-spacing:2px;}
dropdownrole is in this case te class applied to the dropdown menu.
As you see, the dropdown wont apply to the row and just is put above the table (even in the code it's not even in the cell) And I cant wrap my head arround why. I made cells already bigger in size (height and width) but no luck.
Did i do something wrong within the CSS?
EDIT
Per request of the dropdown function.
function MakeUserRoleDropdown($StatusId){
echo "<select name='StatusId' class='dropdownrole'>";
$results = LoadRoles();
while($row = mysql_fetch_array($results)){
echo "<option value='".$row['SgroupId']."' ";
if($StatusId == $row['SgroupId']){
echo "selected='selected'";
};
echo ">".$row['SgroupUser']."</option>";
}
echo "</select>";
}
And here is the output in HTML.
I Think the problem is, that you call MakeUserRoleDropdown which contains echos
you proceed to use this method in this string: echo '<td id="Fright1">'.MakeUserRoleDropdown($StatusId).'</td>';
Alter your MakeUserRoleDropdown to this:
function MakeUserRoleDropdown($StatusId){
$str = '';
$str .= "<select name='StatusId' class='dropdownrole'>";
$results = LoadRoles();
while($row = mysql_fetch_array($results)){
$str .= "<option value='".$row['SgroupId']."' ";
if($StatusId == $row['SgroupId']){
$str .= "selected='selected'";
};
$str .= ">".$row['SgroupUser']."</option>";
}
$str .="</select>";
return $str;
}
And you should be good.

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

PHP only displaying single result from database

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...

Categories