MySQL Joins

Gestart doorOne2xs19 reacties15 weergaven

20 berichten · pagina 1 van 2

One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Ik probeer dus online gasten en leden op te halen maar het gaat nogal mis.

[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] DB[COLOR= #007700]::[/COLOR]query[COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users LEFT JOIN (guests) ON
                            (guests.last_online > DATE_SUB(now(), INTERVAL 5 MINUTE) AND
                             users.last_online > DATE_SUB(now(), INTERVAL 5 MINUTE))"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] DB[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR]fetch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
    try [COLOR= #007700]{[/COLOR] [COLOR= #FF8000]//als lid niet bestaat=gast word er een exception gegooid[/COLOR]
        [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]= new[/COLOR] User[COLOR= #007700]([/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]);[/COLOR]
        [COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]=[/COLOR] false[COLOR= #007700];
    }[/COLOR] catch[COLOR= #007700]([/COLOR]Exception [COLOR= #0000BB]$e[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]=[/COLOR] true[COLOR= #007700];    
    }[/COLOR]
    ?>
    <tr>
        <td style="padding:5px">
            [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]==[/COLOR] true[COLOR= #007700]) {[/COLOR] ?>
                <i>Gast</i>
            [COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] ?>
                <a href="http://<?=$user->get(username)?>.whear.nl/"><?=$user->get(username)?></a>
            [COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?>
        </td>
        <td style="padding: 5px">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$guest[/COLOR][COLOR= #007700]==[/COLOR]false[COLOR= #007700])[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] timeAgo[COLOR= #007700]([/COLOR][COLOR= #0000BB]$user[/COLOR][COLOR= #007700]->[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]last_online[/COLOR][COLOR= #007700]))[/COLOR]?></td>
    </tr>
    [COLOR= #0000BB]<?php[/COLOR]
    [COLOR= #007700]}[/COLOR]
?>


Hij geeft verkeerde namen, dingen dubbel, help!
0
Berichten
7.757
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Raaoul schreef:
Ik probeer dus online gasten en leden op te halen maar het gaat nogal mis.

[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] DB[COLOR= #007700]::[/COLOR]query[COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users LEFT JOIN (guests) ON
                            (guests.last_online > DATE_SUB(now(), INTERVAL 5 MINUTE) AND
                             users.last_online > DATE_SUB(now(), INTERVAL 5 MINUTE))"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] DB[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR]fetch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
    try [COLOR= #007700]{[/COLOR] [COLOR= #FF8000]//als lid niet bestaat=gast word er een exception gegooid[/COLOR]
        [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]= new[/COLOR] User[COLOR= #007700]([/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]);[/COLOR]
        [COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]=[/COLOR] false[COLOR= #007700];
    }[/COLOR] catch[COLOR= #007700]([/COLOR]Exception [COLOR= #0000BB]$e[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]=[/COLOR] true[COLOR= #007700];    
    }[/COLOR]
    ?>
    <tr>
        <td style="padding:5px">
            [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]==[/COLOR] true[COLOR= #007700]) {[/COLOR] ?>
                <i>Gast</i>
            [COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] ?>
                <a href="http://<?=$user->get(username)?>.whear.nl/"><?=$user->get(username)?></a>
            [COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?>
        </td>
        <td style="padding: 5px">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$guest[/COLOR][COLOR= #007700]==[/COLOR]false[COLOR= #007700])[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] timeAgo[COLOR= #007700]([/COLOR][COLOR= #0000BB]$user[/COLOR][COLOR= #007700]->[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]last_online[/COLOR][COLOR= #007700]))[/COLOR]?></td>
    </tr>
    [COLOR= #0000BB]<?php[/COLOR]
    [COLOR= #007700]}[/COLOR]
?>
Hij geeft verkeerde namen, dingen dubbel, help!

Wat is de website?
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Christopher schreef:
Eerdere citaten tonen
Raaoul schreef:
Ik probeer dus online gasten en leden op te halen maar het gaat nogal mis.
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] DB[COLOR= #007700]::[/COLOR]query[COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users LEFT JOIN (guests) ON
                            (guests.last_online > DATE_SUB(now(), INTERVAL 5 MINUTE) AND
                             users.last_online > DATE_SUB(now(), INTERVAL 5 MINUTE))"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] DB[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR]fetch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
    try [COLOR= #007700]{[/COLOR] [COLOR= #FF8000]//als lid niet bestaat=gast word er een exception gegooid[/COLOR]
        [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]= new[/COLOR] User[COLOR= #007700]([/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]);[/COLOR]
        [COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]=[/COLOR] false[COLOR= #007700];
    }[/COLOR] catch[COLOR= #007700]([/COLOR]Exception [COLOR= #0000BB]$e[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]=[/COLOR] true[COLOR= #007700];    
    }[/COLOR]
    ?>
    <tr>
        <td style="padding:5px">
            [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$guest[/COLOR] [COLOR= #007700]==[/COLOR] true[COLOR= #007700]) {[/COLOR] ?>
                <i>Gast</i>
            [COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] ?>
                <a href="http://<?=$user->get(username)?>.whear.nl/"><?=$user->get(username)?></a>
            [COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?>
        </td>
        <td style="padding: 5px">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$guest[/COLOR][COLOR= #007700]==[/COLOR]false[COLOR= #007700])[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] timeAgo[COLOR= #007700]([/COLOR][COLOR= #0000BB]$user[/COLOR][COLOR= #007700]->[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]last_online[/COLOR][COLOR= #007700]))[/COLOR]?></td>
    </tr>
    [COLOR= #0000BB]<?php[/COLOR]
    [COLOR= #007700]}[/COLOR]
?>


Hij geeft verkeerde namen, dingen dubbel, help!
Wat is de website?

Doet er niet toe
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Print screen?
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Afbeelding
Hij toont Whear ookal ben ik ingelogd als Raoul
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
En de db structuur?
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$query = DB::query("SELECT * FROM users LEFT JOIN (guests) ON

Die guests, moet dat niet guests..last_online zijn? Weet er niet veel vanaf, van joins maar kan wel.
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Vriendje schreef:
$query = DB::query("SELECT * FROM users LEFT JOIN (guests) ON

Die guests, moet dat niet guests..last_online zijn? Weet er niet veel vanaf, van joins maar kan wel.
Nee JOIN(xx) is de tablename
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je hebt in je query niks staan dat het id van het lid dat in de afgelopen 5 minuten online was opzoekt. Hij pakt dus altijd het eerste id wat dus van het account whear is
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Luukvdo schreef:
Je hebt in je query niks staan dat het id van het lid dat in de afgelopen 5 minuten online was opzoekt. Hij pakt dus altijd het eerste id wat dus van het account whear is
En hoe kan ik dat doen en vervolgens ophalen met PHP?
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Je bent totaal niet logisch bezig biggrin!

Wat is je structuur van users en guests en wat is de koppelende factor? M.a.w. hoe weet je welke user bij welke gast hoort?

Of sla je gasten op in guests en leden in users en heb je geen wie_is_online-tabel?
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Lennard schreef:
Je bent totaal niet logisch bezig biggrin!

Wat is je structuur van users en guests en wat is de koppelende factor? M.a.w. hoe weet je welke user bij welke gast hoort?

Of sla je gasten op in guests en leden in users en heb je geen wie_is_online-tabel?
guest is gewoon een table met IP en last_online erin.
users is een user table met gewoon last_online
Dus dat laatste yummie
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Dan moet je gewoon 2 select queries doen en die met UNION aan elkaar plakken, maar ik zou een databasemodel maken waarbij ALLE online mensen in een wie_is_online-tabel zitten met evt een userid, en dan kun je gewoon SELECT * FROM wie_is_online doen, met een subquery om de username adhv de user-id op te halen, en als er geen username is (dus als die NULL is) geef je hem Gast oid als username, dan hoef je ook niet telkens new User(id,$fetch[id]); te doen, wat een extra query per user verzorgt lijkt me?
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Lennard schreef:
Dan moet je gewoon 2 select queries doen en die met UNION aan elkaar plakken, maar ik zou een databasemodel maken waarbij ALLE online mensen in een wie_is_online-tabel zitten met evt een userid, en dan kun je gewoon SELECT * FROM wie_is_online doen, met een subquery om de username adhv de user-id op te halen, en als er geen username is (dus als die NULL is) geef je hem Gast oid als username, dan hoef je ook niet telkens new User(id,$fetch[id]); te doen, wat een extra query per user verzorgt lijkt me?
Hmmm, maar hoe update je die tabel dan?
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Gewoon bij elke nieuwe pageview (nieuw = als dat ip nog niet in de tabel staat) een insert, en anders een update met het userid als je die weet?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren