Forum Moderators: coopster
Got some code below i want.
This is how it works:
user enters information into a form.
i then want to work out some values depending on what user has entered.
i want it so that for each individual row the price of adult, price of child, price of oap, price of student are added together and then diplayed in the total column.
Hope you can help
Thanks in advance
$row = pg_fetch_array ($result1);
printf ("<tr> <td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>", $myrow['id'], $myrow['surname'], $myrow['forename'], $myrow['email'], $myrow['adultprices'], $myrow['childprices'], $myrow['studentprices'], $myrow['oapprices'], $myrow['card'], $myrow['expdatemonth'], $myrow['expdateyear'], $myrow['adultprices']+$myrow['childprices']+$myrow['studentprices']);
print "<tr><td>" . $row["id"];
print "<td>" . $row["surname"];
print "<td>" . $row["forename"];
print "<td>" . $row["email"];
print "<td>" . $row["adultprices"];
print "<td>" . $row["childprices"];
print "<td>" . $row["studentprices"];
print "<td>" . $row["oapprices"];
print "<td>" . $row["card"];
print "<td>" . $row["expdatemonth"];
print "<td>" . $row["expdateyear"];
print "<td>" . $row['adultprices']+$row['childprices']+$row['studentprices'];
print "<td>" . $row['adultprices']+$row['childprices']+$row['studentprices'];
<td>with
$row['adultprices']first. Then, it is trying to union that value with
$row['childprices'], and finally union that value with
$row['studentprices']. My guess is you are getting one less cell in your table, right? That's because the union [php.net] is not going to find another <td> in the right-hand values. You want to add the values together, then concatenate the total to your <td>, therefore you are going to have to force the operator precedence [php.net]:
print "<td>" . ($row['adultprices'] + $row['childprices'] + $row['studentprices']);