Double queries

General Chat, Comments
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Double queries

Post 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
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Double queries

Post 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
SophieEV
Posts: 22
Joined: Sat Aug 02, 2014 1:06 pm

Re: Double queries

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Double queries

Post 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!
Post Reply

Return to “General”