0
I am developing a personal messaging system and I need to list the messages I received and the messages I sent, only that I am having difficulties, because the code I did can only get all that I sent or all that I received and never both. The code I’m using
<?php
$query = mysql_query("SELECT pr.id_perfil, pr.id_perfil_enviou, pr.recado, pe.nome as NomeEnviou, prm.nome as NomeRecebeu FROM perfil_recados AS pr INNER JOIN perfil AS pe ON pe.id = pr.id_perfil_enviou INNER JOIN perfil AS prm ON prm.id=pr.id_perfil WHERE (pr.id_perfil='961' AND pr.id_perfil_enviou = '15') OR (pr.id_perfil='15' AND pr.id_perfil_enviou = '961')");
while($exe = mysql_fetch_array($query)){
echo 'De: '.$exe['NomeEnviou'].' para '.$exe['NomeRecebeu'];
}
?>
See, so you shouldn’t have two Select’s?? Because you won’t always send, and it will get an answer. In other words, in just a SELECT for me I don’t think it will...
– Bruno Casali
Consider using the UNION clause of SQL. http://blog.tiagopassos.com/2010/07/20/realizando-duas-ou-mais-consultas-com-union-e-union-all-no-mysql/
– Tony
Thank you @Tony o UNION helped me in what I needed!
– Alisson Acioli