Page 1 of 1

Double queries

Posted: Sat Aug 30, 2014 5:23 pm
by hallsofvallhalla
Man it has been sometime since I have touch PHP and MySQL :P

Why is this

Code: Select all

 $result = $db->Execute("select al.Id,al.Name from user_locations as ul join adventure_locations al where ul.UserId = " . $userId);
    while (! $result->EOF)
    {
        LinkButton($result->fields[1], "index.php?p=adventure&path=" . $result->fields[0]);
        echo "<br>";
        $result->MoveNext();
    }
    $result->Close();
running everything twice? I only have 2 locations

Image

Re: Double queries

Posted: Sat Aug 30, 2014 7:02 pm
by KyleMassacre
Good question lol. I'm kind of running into the same thing with my player shops. It keeps wanting to insert the same row multiple times or double an update qty

Re: Double queries

Posted: Sat Aug 30, 2014 7:47 pm
by SophieEV
Your join dosnt look correct to me, you need to specify how your joining user_locations to adventure_locations otherwise you wont get the location the user is in, but all locations and the userId repeated next to it :)

With the caveat that im more up on mssql so i may be wrong if its at all much different

Re: Double queries

Posted: Sat Aug 30, 2014 10:01 pm
by hallsofvallhalla
haha you are exactly right. Dummy me forgot the on

Code: Select all

 $result = $db->Execute("select al.Id,al.Name from user_locations as ul join adventure_locations al on ul.LocationId = al.id where ul.UserId = " . $userId);
Thanks!

Wahoo I get to use the Thanks Mod!