I have two tables from which I need to display some data in the following manner:
From Table1, I want to select all the users which have the same id_ref. After I selected them, I want to display their number, and then each of them in a list, and also to show how many rows each of them has in Table2, but not all their rows, just certain ones that meet my condition. Also I would like to display the ID of the rows selected from Table2. My code for this is:
$query = 'SELECT * FROM Table1 WHERE id_ref = '.$id_user.' AND active = 1 AND approved = 1 ORDER BY `id_aff` DESC';
$users_brought = mysql_query($query, $conn) or die(mysql_error());
$num_users_brought = mysql_num_rows($users_brought);
while($user_bro = mysql_fetch_assoc($users_brought)):
$query = 'SELECT * FROM Table2 WHERE id_aff = '.$user_bro['id_aff'].' AND ref = '.$income['id_user'].
$user_bro_brought = mysql_query($query, $conn) or die(mysql_error());
$num_user_bro_brought = mysql_num_rows($user_bro_brought);
But something isn't working... Any ideas on this?