Basti Posted November 8, 2008 Share Posted November 8, 2008 Hello everyone, i hope someone is able to help with my problem here. I currently have a code which grabs stuff from 2 different tables of the same database, but its not ordered / sorted the way i want it. I run a topsite and want to display inactive member in my admin area It currently grab Username and days_inactive from 1 table, and title, url, email from another. But it dont add the right title etc to the right username. This is my current code: $result = $DB->select_limit("SELECT ats_stats.username, ats_stats.days_inactive, ats_sites.username, ats_sites.title, ats_sites.url, ats_sites.email FROM ats_sites, ats_stats WHERE ats_stats.days_inactive != 0 ORDER BY ats_stats.days_inactive DESC", $num, 0, __FILE__, __LINE__); while (list($username, $days_inactive, $username, $title, $url, $email) = $DB->fetch_array($result)) { $username_url = urlencode($username); $url_url = urlencode($url); $email_url = urlencode($email); Iam pretty new to php stuff, so forgive me if this might not possible, i simply dont know. So is it possible to change the code like this??? Hope that clear enough, dont know how to explain it else. If table2.username match table1.username then grab url, title, email from table2 and add the correct url, title, email to the username of table1 ( ofc in the output, not the mysql itself Cos currently it grab each url,title,email from table2 and add them randomly to the usernames of table1. that way the inactive usernames are repeated many times as well Thanks, Seb Link to comment https://forums.phpfreaks.com/topic/131904-solved-problem-with-some-code/ Share on other sites More sharing options...
Barand Posted November 8, 2008 Share Posted November 8, 2008 You haven't specified the JOIN condition so every site row is joined with every stats row try SELECT ats_stats.username, ats_stats.days_inactive, ats_sites.title, ats_sites.url, ats_sites.email FROM ats_sites INNER JOIN ats_stats USING (username) WHERE ats_stats.days_inactive != 0 ORDER BY ats_stats.days_inactive DESC Link to comment https://forums.phpfreaks.com/topic/131904-solved-problem-with-some-code/#findComment-685272 Share on other sites More sharing options...
Basti Posted November 8, 2008 Author Share Posted November 8, 2008 Wow, your awsome, that works like a charm, Thanks Link to comment https://forums.phpfreaks.com/topic/131904-solved-problem-with-some-code/#findComment-685294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.