Forum Moderators: coopster

Message Too Old, No Replies

Manipulating rows of information php

Manipulating rows of information php

         

Imy_S3

1:17 am on Mar 19, 2004 (gmt 0)

10+ Year Member



Hi

I have the code below, that gives the prices 2 things.

however i want to add up the values of row 1 so i want price1 + price2 of row1.

how can i do this

hope you can help

thanks in advance

if($nrows1!= 0)
{

print "<table border=20>
<tr>
<th>price 1
<th>price 2\n";

for($j=0; $j<$nrows1; $j++)
{
$row = pg_fetch_array ($result1);

printf ("<tr> <td>%s</td>
<td>%s</td>

</tr>", $myrow['price1'], $myrow['price2']);

print "<tr><td>" . $row["price1"];
print "<td>" . $row["price2"];
print "\n";

}
print"</table>\n";
printf("</form>");

}

mbcx9rvt

2:05 am on Mar 19, 2004 (gmt 0)

10+ Year Member



$total = $myrow['price1'] + $myrow['price2']);

will give you the sum of these two variables into $total

HTH,

mbcx9rvt

Imy_S3

3:01 am on Mar 20, 2004 (gmt 0)

10+ Year Member



This is how i have my code,

i want to add the price of adults + child+ student, and then put it in a variable called total so it can be displayed.

how would i do this.

thanks in advance.

if($nrows1!= 0)
{

print "<table border=20>
<tr>

<th>Adult Price (£)
<th>Child Price (£)
<th>Stutent Price(£)\n";

for($j=0; $j<$nrows1; $j++)
{

$row = pg_fetch_array ($result1);

printf ("<tr> <td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>", $myrow['adultprices'], $myrow['childprices'], $myrow['studentprices']);

print "<tr><td>" . $row["adultprices"];
print "<td>" . $row["childprices"];
print "<td>" . $row["studentprices"];
print "\n";

}
print"</table>\n";
printf("</form>");
}

Birdman

3:14 am on Mar 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I understand correctly...

printf ("<tr> <td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>",
$myrow['adultprices'],
$myrow['childprices'],
$myrow['studentprices'],
$myrow['adultprices']+$myrow['childprices']+$myrow['studentprices']
);

should do what you are asking.

Imy_S3

2:07 pm on Mar 20, 2004 (gmt 0)

10+ Year Member



yes but i wnt the total for each single row, i.e for row 1, row 2 etc with the total in a column called total for each row.

how would i do this

thanks in advance

Imy_S3

3:26 pm on Mar 20, 2004 (gmt 0)

10+ Year Member



This is my code:

printf ("<tr> <td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>", $myrow['adultprices'], $myrow['childprices'], $myrow['studentprices']);

print "<tr><td>" . $row["adultprices"];
print "<td>" . $row["childprices"];
print "<td>" . $row["studentprices"];

This is the solution:

printf ("<tr> <td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>",
$myrow['adultprices'],
$myrow['childprices'],
$myrow['studentprices'],
$myrow['adultprices']+$myrow['childprices']+$myrow['studentprices']
);

How do i pass this down to the row[""] so it actually does it for each row

$myrow['adultprices']+$myrow['childprices']+$myrow['studentprices']