Jump to content

Recommended Posts

hello, how would i add the values off all results in the $pamount array?

 

$result2 = mysql_query("SELECT * FROM pobook WHERE jobnumber = '$jobid'");
while($row2 = mysql_fetch_array($result2))
{
$pamount=$row2['amount'];

  echo "<tr>";
  echo "<td>" . $pamount . "</td>";
  echo "</tr>";


  echo "<tr>";
  echo "<td>VALUE OF ALL RETURNED $pamount HERE</td>";
  echo "</tr>";

Link to comment
https://forums.phpfreaks.com/topic/214571-adding-values-of-array-together/
Share on other sites

Quite easily, akshully . . .

 

$result2 = mysql_query("SELECT * FROM pobook WHERE jobnumber = '$jobid'");
$total = 0;
while($row2 = mysql_fetch_array($result2)) {
$pamount=$row2['amount'];
echo "<tr>";
echo "<td>" . $pamount . "</td>";
echo "</tr>";
$total += $pamount;
}
echo "<tr>";
echo "<td>VALUE OF ALL RETURNED $total HERE</td>";
echo "</tr>";

here is my whole table:

 

echo "<table border='1' style='border-collapse: collapse' bordercolorlight='#000000' bordercolordark='#000000' width='98%' align='center'>";
echo "<tr><td width='100%' colspan='9' align='center'><b>P.O.'s For Job $jobid</b></td></tr>";

echo "<tr>
		<th align='center'>Date</th>
		<th align='center'>Supplier</th>
		<th align='center'>Requested By</th>
		<th align='center'>Address of Job</th>
		<th align='center'>P.O. Number</th>
		<th align='center'>Description</th>
		<th align='center'>Amount</th>
		<th align='center'>Notes</th>
		<th align='center'></th>

</tr>";

$result2 = mysql_query("SELECT * FROM pobook WHERE jobnumber = '$jobid' ORDER BY date");
while($row2 = mysql_fetch_array($result2))
{

  $pid=$row2['id'];
  $pdate=$row2['date'];
  $psupplier=$row2['supplier'];
  $prequestedby=$row2['requestedby'];
  $paddress=$row2['address'];
  $pjobnumber=$row2['jobnumber'];
  $pponumber=$row2['ponumber'];
  $pdescription=$row2['description'];
  $pamount=$row2['amount'];
  $pnotes=$row2['notes'];
  
    $pdate1 = date( 'M j, Y', strtotime($pdate) );
    $total += $pamount;

  echo "<tr>";
  echo "<td align='center'>" . $pdate1 . "</td>";
  echo "<td align='center'>" . $psupplier . "</td>";
  echo "<td align='center'>" . $prequestedby . "</td>";
  echo "<td align='center'>" . $paddress . "</td>";
  echo "<td align='center'>" . $pponumber . "</td>";
  echo "<td align='center'>" . $pdescription . "</td>";
  echo "<td align='right'>" . $pamount . "</td>";
  echo "<td align='center'>" . $pnotes . "</td>";
  echo "<td align='center'><a href='editpo.php?id=".$pid."'>Edit</a>";


  echo "</tr>";
  }
  
    echo "<tr>";

  echo "<td colspan='6' align='right'><b>Total :</td>";
  echo "<td align='right'><b>$" . $total . "</td>";
  echo "<tdcolspan='2'></td>";

  echo "</tr>";
  
  
echo "</table>";


?>

You missed a line from the first example. It was pretty obscure, but it kinda needs to be there. Should take care of the error.

 

$result2 = mysql_query("SELECT * FROM pobook WHERE jobnumber = '$jobid' ORDER BY date");
$total = 0; // << -----ADD THIS ----------<< //
while($row2 = mysql_fetch_array($result2))

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.