Jump to content

[SOLVED] Problem with some code


Basti

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.