Originariamente inviato da sys14
Salve,
ho un db avente tre tabelle ovvero:
- users (id e username) -> dove ogni id è associato all'username
- settings (id_user e url_image) -> dove ogni id_user è associato un URL ad una immagine
- friends ( id_following e id_follower )
Vorrei visualizzare tutti gli id_following, quindi l'username e l'url_image, di un determinato id_follower
Questa è la query che ho provato a scrivere:
codice:
SELECT url_image, users.id, users.username FROM settings, users, friends WHERE id_follower = 5 AND settings.id_user = id_following AND users.id = id_following
.. dovrebbe visualizzare url_image, l'id dell'utente e il suo relativo username che è in relazione (following) dell'utente con id = 5
Infine questo è il codice PHP che dovrebbe portare alla risoluzione del problema:
Codice PHP:
public function listFollowing( $ris_ = NULL)
{
if ( $ris_ == NULL )
{
$SQL = "SELECT url_image, users.id, users.username FROM settings, users, friends WHERE id_follower = $this->id AND settings.id_user = id_following AND users.id = id_following";
$ris_ = $this->doQuery( $SQL );
if ( !mysql_num_rows( $ris_ ) )
echo 'noUserfollowing';
}
while ( $row = mysql_fetch_array( $ris_ ) )
{
return array( $ris_, $row['url_image'], $row['id'], $row['username'] );
}
return array( NULL, NULL, NULL, NULL );
}