MadTechie Posted October 28, 2008 Share Posted October 28, 2008 Its probably needs some tweaks but the problem was basically the first total were infact the totals from the second couon_id, below is the final version (remove an unneed if & query) basically i echo the last totals (first one is blank) then get the totals at the same time the coupon id changes, but as were out the loop before the next titles we just echo the last totals final code below <?php /*REMOVE BELOW*/ mysql_connect("localhost","solon","solon"); mysql_select_db("solon"); $memb_id =22; $agn_id = 230457; /*REMOVE ABOVE*/ $result = mysql_query("SELECT * FROM `coupons` WHERE `member_id` = '$memb_id' && `agent_id` = '$agn_id' ORDER BY coupon_id") or die(mysql_error()); $previd = ''; $data = ""; echo '<table border="0">'; while(($row = mysql_fetch_assoc($result))) { //titles & Totals if($row['coupon_id'] != $previd) { //Totals echo $data; $previd = $row['coupon_id']; $data = BuildTotals($previd); //titles echo "<tr>"; echo "<td colspan='3'><u><b>Coupon Id:</b>{$row['coupon_id']}</u></td>"; echo "</tr>"; echo "<tr>"; echo " <td width='260'><u><b>Game</b></u></td>"; echo " <td width='100'><u><b>Bet</b></u></td>"; echo " <td width='40'><u><b><u><b> Winings </b></u></b></u></td>"; echo "</tr>"; } //results echo "<tr>"; echo " <td>{$row['event']}</td>"; echo " <td>{$row['bet']}</td>"; echo " <td align='right'>{$row['winings']}</td>"; echo "</tr>"; } echo $data; echo "</table>"; function BuildTotals($previd) { $data =""; $result_o = mysql_query("SELECT * FROM `coupon_winnings` WHERE `coupon_id` = '$previd' ORDER BY `coupon_id`"); while($row_o = mysql_fetch_assoc($result_o)) { $data .= "<tr><td> </td><td bgcolor='#CCCCCC'><b><u>Total:</b></u></td><td bgcolor='#CCCCCC' align='right'>{$row_o['total_winings']}</td></tr>"; $data .= "<tr><td> </td><td bgcolor='#CCCCCC'><b><u>Stake:</b></u></td><td bgcolor='#CCCCCC' align='right'>{$row_o['stake']}</td></tr>"; $data .= "<tr><td> </td><td bgcolor='#CCCCCC'><b><u>Possible Winnings:</b></u></td><td bgcolor='#CCCCCC' align='right'>{$row_o['poss_total_winnings']}</td></tr>"; $data .= "<tr><td> </td><td> </td><td> </td></tr>"; $data .= "<tr><td> </td><td> </td><td> </td></tr>"; } return $data; } Quote Link to comment https://forums.phpfreaks.com/topic/130405-solved-records-display-problem/page/2/#findComment-676769 Share on other sites More sharing options...
solon Posted October 28, 2008 Author Share Posted October 28, 2008 Again thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/130405-solved-records-display-problem/page/2/#findComment-676794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.