Jump to content

[SOLVED] Records Display Problem


solon

Recommended Posts

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;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.