Query Help

    Date: 12/13/05 (PHP Community)    Keywords: mysql, sql

    I am not very experienced at writing queries that pull from several tables...

    Can anyone tell me why $maillist has 639 results when it should have only 8 (where assgo.aprivi='m') ?

    code

    $maillist = array();
    
    $Link = mysql_connect ($Host, $User, $Password);
    
    $Query = "SELECT fb_user.emailAddress, fb_user.ustatus, passgo.aprivi, member_services.salesAlert 
    FROM fb_user, passgo, member_services 
    WHERE fb_user.ustatus='active' AND passgo.aprivi='m' AND member_services.salesAlert='y' 
    ";
    
    $Result = mysql_db_query ($DBName, $Query, $Link);
    
    if (!$Result) {
    print("$Query
    \n"); echo 'MySQL Error: ' . mysql_error(); exit; } while($Row = mysql_fetch_array ($Result)) { $email = $Row['emailAddress']; $type = $Row['aprivi']; $send = $Row['salesAlert']; $maillist[] = array($email, $type, $send); } mysql_close ($Link);



    Solution:

    $Query = "SELECT 
    u.userID, 
    u.emailAddress, 
    ui.cats, 
    p.aprivi, 
    ms.salesAlert 
    FROM fb_user AS u 
    INNER JOIN passgo AS p ON u.userID = p.goID 
    INNER JOIN member_services AS ms ON u.userID = ms.serviceID 
    LEFT JOIN fb_user_interest AS ui ON u.userID = ui.userID 
    WHERE u.ustatus='active' 
    AND p.aprivi='m' 
    AND ms.salesAlert='y'";
    

    Source: http://www.livejournal.com/community/php/378930.html

« Best Practice for a dynamic... || Why isn't this working? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home