1
I’m new with sql and php.
is the following, I have an affiliate system that I need to bring a user’s affiliate list.
for that use:
<?php
//traz os usuarios
$query = sprintf("SELECT referral_user_id FROM magry_awoaffiliate_referral where affiliate_user_id = '$userid'");
$dados = mysql_query($query, $con) or die(mysql_error());
$linha = mysql_fetch_assoc($dados);
$total = mysql_num_rows($dados);
$teste = $linha['referral_user_id'];
?>
<?php
if($total > 0) {
do {
?>
<ul>
<li><?=$linha['referral_user_id']?></li>
</ul>
<?php
}while($linha = mysql_fetch_assoc($dados));
}
mysql_free_result($dados);
?>
This query brings me the list of Ids of this user, but I need to get the name of each user that is in another table (magry_users).
How do I bring this information?
In the affiliate table, I have the referral_user_id that does not have its name and in the magry_users table I have the id (which is the same id of referral_user_id) and the user name.
I want to bring the name here:
<li><?=$linha['referral_user_id']?> - "nome do usuario"</li>
Thank you!
You can use
INNER JOIN
, example: http://blog.thiagobelem.net/relations-tabelas-no-mysql– Leonardo Rodrigues