Ciao a tutti.
Dovrei sommare le 2 colonne che contengono soldi stampando per ogni utente nome, guadagni propri, guadagni da Referrers.
dovrei sommare earnings.ear_value WHERE ear_usr_id='$userID' && ear_status_id='1'
+ referrers.ref_value WHERE ref_usr_id='$userID' && ref_status_id='1'
Devono essere 2 valori distinti, vengono sommati nella pagina.
Vi post anche le tabelle, magari qualcuno riesce a capire dove sbaglio.
Grazie
codice:
CREATE TABLE IF NOT EXISTS `referrers` (
`ref_id` int(10) unsigned NOT NULL,
`ref_usr_id` tinyint(10) NOT NULL,
`ref_my_id` tinyint(10) NOT NULL,
`ref_date` date DEFAULT NULL,
`ref_value` float(10,2) DEFAULT '0.00',
`ref_status_id` tinyint(1) unsigned DEFAULT '1'
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
codice:
CREATE TABLE IF NOT EXISTS `earnings` (
`ear_id` int(10) unsigned NOT NULL,
`ear_sia_id` int(10) unsigned DEFAULT NULL,
`ear_usr_id` tinyint(10) NOT NULL,
`ear_date` date DEFAULT NULL,
`ear_value` float(10,2) DEFAULT '0.00',
`ear_pay` float(10,2) NOT NULL DEFAULT '0.00',
`ear_user` float(10,2) NOT NULL DEFAULT '0.00',
`ear_site` float(10,2) NOT NULL DEFAULT '0.00',
`ear_ref` float(10,2) NOT NULL DEFAULT '0.00',
`ref_id` int(10) unsigned NOT NULL DEFAULT '1',
`ear_status_id` tinyint(1) unsigned DEFAULT '1'
) ENGINE=InnoDB AUTO_INCREMENT=287 DEFAULT CHARSET=utf8;
Codice PHP:
<?php $conn = new mysqli($host, $username, $password, $db_name);
$q="SELECT usr_pay, usr_id, usr_name, ear_usr_id, ear_status_id, SUM(ear_user) as e_usr, SUM(ref_value) as e_ref FROM earnings, users, refferers WHERE ear_status_id='1' && ear_usr_id=usr_id && usr_pay=80 GROUP BY ear_usr_id, ref_my_id ORDER BY e_tot DESC";
$result = $conn->query($q); // output data of each row
while($row = $result->fetch_assoc("SELECT SUM(ref_value) as e_ref FROM referrers WHERE ref_ref_id=usr_id")) {
$total = $row["e_usr"]+$row["e_ref"];
echo "<tr> <td> ".$row["usr_name"]."</td>
<td> ".$row["e_usr"]." RON</td>
<td> ".$row["e_ref"]." RON</td>
<td> ".$total."</td>
<td> <input type='submit' class='alt_btn' value='Plătește' /></td>
</tr>";
}
echo "</tbody>";
?>