Forum Moderators: coopster
I am using the script below to try achieve the following:
1. I want to total the amount column
2. I want to subtract distance2 form distance1 to arrive at the distance travelled
3. I need to have decimals automatically placed in the fields as well
All efforts to date have produced weird and wonderful results. As usual any help greatly appreciated.
===============================================
<table border="0" width="800" id="table1" style="font-family:arial" style="font-size:8pt"
div align="center">';
echo '<tr>';
echo '<th bgcolor="#C0C0C0" style="text-align:left;">Registration</th>';
echo '<th bgcolor="#C0C0C0" style="text-align:left;">Distance1</th>';
echo '<th bgcolor="#C0C0C0" style="text-align:left;">Distance2</th>';
echo '<th bgcolor="#C0C0C0" style="text-align:left;">Oil</th>';
echo '<th bgcolor="#C0C0C0" style="text-align:left;">Amount</th>';;
echo '</tr>';
$sql ="select * from `petrol` where $method like '%$text%'";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)){
echo "
<tr>
<td>".$row['reg']."</td>
<td>".$row['distance1']."</td>
<td>".$row['distance2']."</td>
<td>".$row['oil']."</td>
<td>".$row['amount']."</td>
<td><a href='edit_news.php?id=".$row['id']."'>Edit</a></td>
</tr>";
1. I want to total the amount column
I want to subtract distance2 form distance1 to arrive at the distance travelled
I need to have decimals automatically placed in the fields as well
Another alternative would be to do the math within the SQL query.
$tamount = 0;
$sql ="select * from `petrol` where $method like '%$text%'";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)){
$tamount += $row['amount'];
echo "
<tr>
<td>".$row['reg']."</td>
<td>".$row['distance1']."</td>
<td>".$row['distance2']."</td>
<td>".$row['oil']."</td>
<td>".$row['amount']."</td>
<td><a href='edit_news.php?id=".$row['id']."'>Edit</a></td>
</tr>";
As for the last two, can you clarify a bit more? Like for distance traveled will you want that for each row or for the total at the end? For number format can you give some examples? Do you just want an arbitrary 2 decimals added to the end or some pattern?