I have a json file I am getting returned from an API. I have learnt how to format it and lay it out in PHP but one bit I can't work out is how to reformat the date that is returned.
This is the page that displays the results:
<body>
<h1 align="center"><font face ="Arial"><u><br>Results<br><br></u>Postcode - <?php echo $resultData['postcode']; ?></font></h1>
<br>
<br>
<h2 align="center">Known Floor Sizes Listed By Report Date</h2>
<br>
<table class= "general" align= "center" bgcolor="#ffffff">
<tr>
<td align="center" rowspan="2"><b>Inspection Date</b></td>
<td align="center" rowspan="2"><b>Address</b></td>
<td align="center" colspan="2"><b>Size in</b></td>
</tr>
<tr>
<td align="center"><b>SqM</b></td>
<td align="center"><b>SqFt</b></td>
</tr>
<?php foreach ($resultData['known_floor_areas'] as $property) { ?>
<tr>
<td align="center"><?php echo $property['inspection_date']; ?></td>
<td align= "left" ><?php echo $property['address']; ?></td>
<td align="center"><?php echo (round($property['square_feet'] * 0.092903,0));?></td>
<td align="center"><?php echo $property['square_feet']; ?></td>
</tr>
<?php } ?>
</table>
</body>
This displays the date in the format: 2015-06-22T23:00:00.000000Z
I want to change the format to a basic: 2015-06-22
I'm sure it's simple but after a lot of searching I'm going round in circles.
Use DateTime() then format() it:
<td align="center"><?php echo (new DateTime($property['inspection_date']))->format('Y-m-d'); ?></td>
Related
Im trying to teach myself php.... I have created a database with 4 elements... region, details, store_name, web_address.
I have created ado-while loop that displays all the records in a 'region'... it displays 'store_name', then 'web_address', then 'details' sorted so all the records with the same 'details' are grouped together;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<tr>
<td width="14">
<td width="313"><?php echo $row_RegionList['details']; ?> </tr>
<?php } while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
I now want to make it so every record with the same 'details' value get listed under a 'details' sub heading.
This is my attempt;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php $details = $row_RegionList['details'];
do { ?>
<tr>
<td width="313"> <h3><?php echo $row_RegionList['details']; ?> </h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<?php } while ($row_RegionList['details'] == $details);
$details = $row_RegionList['details'];
} while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
This makes a heading of 'region' with a sub heading of 'details' but then creates an eternal loop of the first record in the database. can someone show me what I have done wrong?
I am trying to design the table but it seems coming into proper way but for some cases. In this table, that $cal_amount and $cal_amount_key part shouldbe print whole for any numbers of cars.
Code:
PHP
<?php
$TotV=array("car","bus","jeep");
$Nopkg=array(759,159,459);
$Avg=array(20,50,15);
$Qty=array(15000,58000,58922);
$rate=array(31.73,17.15,17.25);
$gro_tot=789456;
$Cex=781254;
$S_Tot=159254;
$Vat=12500;
$frieght=0;
$G_Tot=985251;
?>
CSS
table,td,th,tr {
border:1px solid black;
border-collapse: collapse;
text-align:left;
}
HTML
<table>
<tr>
<th>S.No</th><th align="center">Variety of Goods</th><th style="width:70px">No.and Description of<br/>Packages</th><th style="width:70px">Avg. Contents per Package<br/>(Pcs)</th><th style="width:70px">Total Quantity<br/>(Pcs)</th><th style="width:70px">Rate per pc.</th><th colspan="2" style="text-align:center;">Amount<br/>(Rs.)</th>
</tr>
<?php
for($i=0;$i<count($TotV);$i++)
{?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo strtoupper($TotV[$i]);?></td>
<td><?php echo $Nopkg[$i];?></td>
<td><?php echo $Avg[$i];?></td>
<td><?php echo $Qty[$i];?></td>
<td><?php echo $rate[$i];?></td>
<?php
}?>
<td colspan="1">Total Value</td><td style="width:100px;text-align:right;"> <?php echo $gro_tot;?></td>
<tr><td></td><td></td>
<td></td><td></td><td></td><td></td><td style="width:150px;">C.Ex.Duty 12.5%</td><td style="width:150px;text-align:right;"> <?php echo $Cex;?></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td></td><td style="width:150px;">SubTotal</td><td id="num" style="width:150px;text-align:right;"> <?php echo $S_Tot;?></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td style="width:150px;">VAT/CST 2%</td><td style="width:150px;text-align:right;"> <?php echo $Vat;?></td></tr>
<tr><td style="border:none;" colspan="3"><b>qwert</b></td><td style="border:none;"></td><td style="border:none;" colspan="2"><td><b>Freight</b></td><td style="width:150px;text-align:right;"> <STRONG><?php echo $frieght;?></STRONG></td></tr>
<tr><td style="border:none;" colspan="3"><b>asdf</b></td><td style="border:none;"></td><td style="border:none;" colspan="2"><td><b>Grand Total</b></td><td style="width:150px;text-align:right;"> <STRONG><?php echo $G_Tot;?></STRONG></td></tr>
</tr>
</table>
Please suggest some changes to be done in code so that It will start from first row instead of third row. Thanks in advance.
Try this:
First make PHP array for total calculation and label.
$TotV=array("car","bus","jeep");
$Nopkg=array(759,159,459);
$Avg=array(20,50,15);
$Qty=array(15000,58000,58922);
$rate=array(31.73,17.15,17.25);
$gro_tot=789456;
$Cex=781254;
$S_Tot=159254;
$Vat=12500;
$frieght=0;
$G_Tot=985251;
$cal_amount_key = array('Total Value',
'C.Ex.Duty 12.5%',
'SubTotal',
'VAT/CST 2%',
'Freight',
'Grand Total');
$cal_amount = array($gro_tot,
$Cex,
$S_Tot,
$Vat,
$frieght,
$G_Tot);
Put the code inside loop:
<table>
<tr>
<th>S.No</th>
<th align="center">Variety of Goods</th>
<th style="width:70px">No.and Description of<br/>Packages</th>
<th style="width:70px">Avg. Contents per Package<br/>(Pcs)</th>
<th style="width:70px">Total Quantity<br/>(Pcs)</th>
<th style="width:70px">Rate per pc.</th>
<th colspan="2" style="text-align:center;">Amount<br/>(Rs.)</th>
</tr>
<?php
for($i=0;$i<count($TotV);$i++) {?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo strtoupper($TotV[$i]);?></td>
<td><?php echo $Nopkg[$i];?></td>
<td><?php echo $Avg[$i];?></td>
<td><?php echo $Qty[$i];?></td>
<td><?php echo $rate[$i];?></td>
<td><?php echo $cal_amount_key[$i];?></td>
<td style="width:100px;text-align:right;"><?php echo $cal_amount[$i];?></td>
</tr>
<?php } ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td style="width:150px;">VAT/CST 2%</td>
<td style="width:150px;text-align:right;"> <?php echo $Vat;?></td>
</tr>
<tr>
<td style="border:none;" colspan="3"><b>qwert</b></td>
<td style="border:none;"></td>
<td style="border:none;" colspan="2">
<td><b>Freight</b></td>
<td style="width:150px;text-align:right;"> <STRONG><?php echo $frieght;?></STRONG></td>
</tr>
<tr>
<td style="border:none;" colspan="3"><b>asdf</b></td>
<td style="border:none;"></td>
<td style="border:none;" colspan="2">
<td><b>Grand Total</b></td>
<td style="width:150px;text-align:right;"> <STRONG><?php echo $G_Tot;?></STRONG></td>
</tr>
</table>
I've stucked a bit when it comes to a small piece of my PHP code. The role of this script is to display whole table from mysql plus adding to each row a hyperlink to delete such row.
<?php
$connection=mysql_connect('localhost','root','') or die(mysql_error());
error
mysql_select_db('localhost_db',$connection) or die(mysql_error());
$query=mysql_query("SELECT * FROM cms_contest") or die(mysql_error());
if(mysql_num_rows($query)>0):
?>
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php
while($row=mysql_fetch_object($query)):?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">REMOVE</td>
</tr>
<?php endwhile;?>
</table>
<?php
else: ?>
<h3>No Results found.</h3>
<?php endif; ?>
It would be perfect if there appear a short javascript popup with question like: are you sure you want to remove this entry? OK / Cancel.
I have no clue how to do it.. thanks for any tips!
Simple/stupid method:
<td>nuke me</td>
But if a web spider or a browser link pre-fetch tool gets loose on this page, you'll be nuking ALL of your records.
Somewhat better:
<td>
<form method="post" action="deleteme.php">
<input type="hidden" name="id" value="<?php echo $row->ID ?>" />
<input type="submit" value="Nuke me" />
</form></td>
And then there's various options involving radio buttons/checkboxes, or JS to trap the click-on-the-link etc...
But, in the end, they ALL boil down to "you have to sent the ID of the row back to the server". How you go about that is up to you... just don't use the plain "click here" version.
Indeed there are several different ways to do this. One way I like is to wrap the entire table in a form that submits to the delete script, and use a button for each row with the row ID as its value.
<form method="post" action="delete.php">
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php while($row=mysql_fetch_object($query)): ?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">
<button name="delete-id" type="submit" value="<?php echo $row->ID; ?>">
REMOVE
</button>
</td>
</tr>
<?php endwhile;?>
</table>
</form>
There are also many different ways to confirm the deletion. The simplest I know of on the client side is to add onclick="return confirm('Are you sure?');" to the delete button.
click event:
DELETE
<script type="text(javascript">
function confirmDelete(id){
if(confirm('sure u want to delete entry with id: ' + id + '?')){
window.location.href = "ursite.php?id="+id+"&delete=true";
}
}
</script>
PHP
if(isset($_GET['delete'])){
$stmt = "DELETE FROM cms_contest WHERE ID = ".$_GET['id'];
mysql_query($stmt);
}
it's the worst way to do it.
I recommend you to look at:
jQuery $.post()jQuery $.ajax()
I hope it will help you.
I m inserting the data in description in magento...!!
but I'm getting a paragraph...!!
but inorder to get tabular format I had to write the HTML code manually.
So is there any solutions to get the tabular format autmatically.
For example follow below pic:
Create maximum attributes for specification add those.
like spec_1.spec_2,......
then display those attributes values in specification section in table format.
For example:
<table class="data-table" id="product-attribute-specs-table-4">
<col width="25%" />
<col />
<tbody>
<?php if (0 == strcmp($attributeSetName, 'Clothing')): ?>
<tr>
<th class="label">Clothing Shape</th>
<td class="data"><?php echo $_product->getClothing_shape() ?></td>
</tr>
<tr>
<th class="label">Outer Fabric</th>
<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
</tr>
<tr>
<th class="label">Clothing Lining</th>
<td class="data"><?php echo $_product->getClothing_lining() ?></td>
</tr>
<?php elseif (0 == strcmp($attributeSetName, 'Sleeping Bags')): ?>
<tr>
<th class="label">Outer Fabric</th>
<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
</tr>
<tr>
<th class="label">Inner Fabric</th>
<td class="data"><?php echo $_product->getInner_fabric() ?></td>
</tr>
<tr>
<th class="label">Filling</th>
<td class="data"><?php echo $_product->getFilling() ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table-4')</script>
i am working on a project which is airways ticketing.
i am able to display the final ticket to the user but how can i give user the ability to print it when he/she clicks on print button.
please help..
<title>Untitled Document</title>
<style type="text/css">
#main {
position:absolute;
top:100px;
width:100%;
height:250px;
z-index:1;
}
#submit {
position:absolute;
top:300px;
width:100%;
height:42px;
z-index:2;
}
</style>
</head>
<body>
<div id="main" align="center">
<?PHP
mysql_connect("127.0.0.1","root","");
mysql_select_db("cmc");
$id=$_REQUEST['id'];
$r=mysql_query("select * from manifest where transid=".$id);
$d=mysql_fetch_assoc($r);
?>
<table width="800" border="1">
<tr>
<td colspan="6" align="center">HORIZON AIRWAYS PASSENGER TICKET</td>
</tr>
<tr >
<td colspan="3" align="center">PNR NUMBER: </td>
<td colspan="3" align="center"><?php echo $d["pnrno."]; ?></td>
</tr>
<tr >
<td colspan="3" align="center"> PASSENGER'S NAME:</td>
<td colspan="3" align="center"><?php echo $d["name"]; ?></td>
</tr>
<tr >
<td colspan="3" align="center">DATE OF ISSUE:</td>
<td colspan="3" align="center"><?PHP
ini_set('date.timezone','asia/calcutta');
echo date("d/m/y"); ?></td>
</tr>
<tr >
<td colspan="3" align="center">TIME OF ISSUE:</td>
<td colspan="3" align="center"><?PHP
echo date("h/i/s"); ?></td>
</tr>
<tr >
<td colspan="3" align="center">DATE OF JOURNEY:</td>
<td colspan="3" align="center"><?php echo $d["day"]."-".$d["month"]."-".$d["year"]; ?> </td>
</tr>
<tr>
<td colspan="6" align="center">NOT TRANSFERRABLE</td>
</tr>
<tr>
<td colspan="3" align="center">PASSENGER NAME:</td>
<td colspan="3" align="center"><?php echo $d["name"]; ?></td>
</tr>
<tr>
<td colspan="3" align="center">SECTOR:</td>
<td colspan="3" align="center"><?php echo $d["sector"]; ?></td>
</tr>
<tr>
<td width="134" align="center">FLIGHT #</td>
<td width="132" align="center">CLASS</td>
<td width="112" align="center">DATE</td>
<td width="130" align="center">DEP. TIME</td>
<td width="132" align="center">ARR. TIME</td>
<td width="120" align="center">STATUS</td>
</tr>
<tr>
<td><?php echo $d["flight_no."]; ?></td>
<td><?php echo $d["class"]; ?></td>
<td><?php echo $d["name"]; ?></td>
<td><?php echo $d["departure"]; ?></td>
<td><?php echo $d["arrival"]; ?></td>
<td><?php echo "confirm"; ?></td>
</tr>
</table>
<div id="submit" align="center">
<form name="form1" method="POST">
<input type="submit" value="Print" name="submit"/>
</form>
</div>
</div>
</body>
</html>
Printing has to be done on the client side, not the server side. This shouldn't be a form (I would actually make it a link). The simplest method:
<input type="submit" value="Print" onclick="print(); return false;"/>
You can trigger the print event bij using the javascript function: window.print().
Example:
print page
TIP!
Use a print CSS to tell the browser what to print! That way the user doesn't waste paper ;)
Example including a print CSS stylesheet: <style type="text/css" media="print" href="print.css" />
More info about CSS print stylesheets: http://www.alistapart.com/articles/goingtoprint/
You can invoke printing via javascript using print method
Click to Print This Page
You might want to hide certain elements in page when printing it. For that you can use css like so:
#media print {
.non-printable { display: none; }
}
And then give non-printable class to those elements that you don't want printed.
The others are correct that this would be done with
print ticket
You will also probably want to create a separate CSS style for the print version that strips out unnecessary graphics. You can also add manual page breaks in case there are individual boarding passes or something.
<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />