开发者

Same Data Appear only once

I have the following code which produces following output:-

<?
$tablaes = mysql_query("SELECT * FROM members where id='$order[user_id]'"); 
$user = mysql_fetch_array($tablaes);
$idsd=$user['id'];
$rPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE type!='rent_referral'开发者_开发技巧 AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'");
$hdPaid = mysql_fetch_array($rPaid);
$sPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE user_id='$idsd' AND type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'");
while ($hPaid = mysql_fetch_array($sPaid)) { 
?>

<td><?=$user['username']?></td>
<td><?=$hPaid['total']?></td>
<?  
}
?>

</tr>

It appears like this http://dl.dropbox.com/u/14384295/darrenan.jpg

I want same data to appear only once..

Like Username: Vegas and price with him only once.


Try to change

$sPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE user_id='$idsd' AND type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'");

to

$sPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE user_id='$idsd' AND type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "' GROUP BY user_id");


Change it

$sPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE user_id='$idsd' AND type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'");

to

$sPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE user_id='$idsd' AND type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "' limit 1");


Change to $tablae = mysql_query("SELECT * FROM order_history where date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "' GROUP BY user_id");

Sorry didn't add tablae in the first post. anyway solved.


You can use "DISTINCT " in Select query to avoid repetition of data in the result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜