I have two tables in mysql.
people is an identification table of users.. names/etc
trans is a transaction table, what the users have done (add/subtract balances)
I am wanting to return every "ident" from people, then search trans for that ident's matching rows, and then after all are returned, echo the page break, so each person gets their own page print out. (there shouldn't be so many transactions that a page is not enough..) Also to subquery the balance remaining (trans has both credits and debits, could be positive or negative).
Structure:
people.id #(not queried, unique/auto-increment)
people.name
people.location
people.ident #(assigned number that is same as trans.ident)
trans.id #(not queried, unique/auto-inc)
trans.date
trans.ident
trans.amount
trans.description
Queries:
$query = "SELECT people.ident, people.name, people.location, trans.ident, trans.date, trans.amount, trans.description FROM people LEFT JOIN trans ON people.ident = trans.ident";
$balance = mysql_result(mysql_query("SELECT SUM(amount) FROM trans WHERE ident = $ident", $dblink), 0);
$result = mysql_query($query) or die(mysql_error());
Echo results:
while($row = mysql_fetch_array($result)){
echo $row['name']. " - ". $row['ident']. " - ". $row['amount']. " - " .row['description'];
echo('<div style="page-break-before: always;"></div>');
}
This will print out each transaction, and they are sorted by the ident, but with div after each... I would like to print out the name and location, also their remaining balance ( once on a div.. and then trans under like so:
<div class="user">['name'] ['location'] $balance</div> #These aren't rows, just a single return
<div class="trans">$row['amount']. " - ". $row['description'];</div>
<div style="page-break-before: always;"></div>
Thanks for any assistance!