I know the question is already answered but the complexity with me is a bit high. I have a table with 5 columns the rows can be any number. The data retrieved from the database is based on a certain condition and the output is sequential. What I need to do is I have to display 2 rows retrieved from db side by side, as a result now we will have 10 columns in total. I have to do this for all the rows. So if there are 10 rows in db there will be 5 rows on php as every second row is placed side.
Now the thing is the fifth and the tenth column is having unix timestamp. I have to substract the unix time in the fifth column from the unix timestamp in the 10 column and display as a difference in the 11 column on a PHP screen. The code that I wrote displays all the rows sequentially. I am not sure on how to do this. Need help!!// I am not a developer I am into performance Testing. Just have to get this done.. :(.. Please find my PHP code below (Database snapenter image description here) (Expected outputenter image description here) in the expected after the 10'th column i need a difference column. Which calculates the difference between 10th and fifth column. Thanks in advance..
<?php
include '_runQuery.php';
$host="10.139.157.84";
$username="testadmin";
$password="summer12";
$db_name="pvteamdb";
$printLimit = 100000;
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$application =$_POST['application'];
$lifecycle =$_POST['lifecycle'];
$useability =$_POST['useability'];
// 'application' needs to have a value ...
if ( $application == "" ) {
echo "<br><br> *ERROR: you must enter an application id !! ** " ;
echo "<br><br><a href='print_selected_policies.php'>Back</a>";
return;
}
$sqlfirstbit = "SELECT application,identifier,lifecycle,useability,epochtime FROM policies WHERE application = '$application'";
$orderByStmt = " order by identifier asc";
if ( $lifecycle == "" && $useability == "" ){
$sql = $sqlfirstbit . $orderByStmt;
} else if ( $useability == "" ){
$sql = $sqlfirstbit . " AND lifecycle = '$lifecycle' " . $orderByStmt;
} else if ( $lifecycle == "" ){
$sql = $sqlfirstbit . " AND useability = '$useability' " . $orderByStmt;
} else {
$sql = $sqlfirstbit . " AND lifecycle = '$lifecycle' AND useability = '$useability' " . $orderByStmt;
}
$result=runQuery($sql);
$numRows=mysql_num_rows($result);
echo "<br><br> numRows = ". $numRows;
if ($numRows > $printLimit ){
echo "<br><br> *ERROR: more than $printLimit rows have been returned from query ($numRows rows returned)** " ;
echo "<br><br><a href='print_selected_policies.php'>Back</a>";
return;
}
if ($numRows == 0){
echo "<br><br> -- No rows match filter criteria -- ";
} else {
echo "<table border='1'>";
echo "<tr><td>application</td><td>identifier</td><td>lifecycle</td><td>useability</td><td>epochtime</td></td>";
echo "</tr>";
// $rows=mysql_fetch_array($result);
while ($row = mysql_fetch_assoc($result)){
$application= $row['application'];
$identifier = $row['identifier'];
$lifecycle = $row['lifecycle'];
$useability = $row['useability'];
//$otherdata = htmlspecialchars($row['otherdata']);
//$otherdata =$row['otherdata'];
//$lifecycle = $row['lifecycle'];
//$created = $row['created'];
//$updated = $row['updated'];
$epochtime = $row['epochtime'];
echo "<tr>";
echo "<td>$application</td>";
echo "<td>$identifier</td>";
echo "<td>$lifecycle</td>";
echo "<td>$useability</td>";
//echo "<td>$otherdata</td>";
//echo "<td>$created</td>";
//echo "<td>$updated</td>";
echo "<td>$epochtime</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
}`enter code here`
echo "<br><br><a href='message_analyzer.php'>Back</a>";
mysql_close();
?>