[PHP] Herhalen in query

Gestart doorCees8 reacties44 weergaven

9 berichten · pagina 1 van 1

Cees

Lid · Topicstarter

Berichten
103
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi,

Ik heb wat geselecteerd uit de database met de query:

[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id FROM members WHERE posts < 16"[/COLOR][COLOR= #007700]);[/COLOR] ?>


Hier komen een aantal ids uit, nou wil ik dat die ids weer in een andere query komen namelijk:

[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM forum WHERE uid ="[/COLOR][COLOR= #007700]);[/COLOR] ?>


Het moet dan komen bij WHERE uid=
Heb al wat dingen geprobeerd maar kom er niet uit. Of moet het met LEFT JOIN ?
0
Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

[COLOR= #0000BB]<?php
$members[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id FROM members WHERE posts < 16"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM forum WHERE uid ="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$members[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
?>


zoiets?
Ik snap je niet helemaal
0
Cees

Lid · Topicstarter

Berichten
103
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
wil niet,

Kijk ik haal met de query een aantal ids op wie minder dan 15 posts op een forum hebben.
Daarna wil ik uit een andere tabel alles selecteren met het uid(Userid) die ik net heb opgehaald.

Zo duidelijk?
0
Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

Ow zo wacht dit is wel een grote omweg maar ik doe het altijd zo:

[COLOR= #0000BB]<?php
$members[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id FROM members WHERE posts < 16"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$member2[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$members[/COLOR][COLOR= #007700])) {[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM forum WHERE uid ="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$member2[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]uid[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);
}[/COLOR]
?>
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
@^: Doe het dan wel zo:

[COLOR= #0000BB]<?php
$members[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id FROM members WHERE posts < 16"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$member[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$members[/COLOR][COLOR= #007700])) {[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM forum WHERE uid ="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$member[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);
}[/COLOR]
?>
0
Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

Wat is daar dan anders?
0
Berichten
1.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
van $member2 maakt hij $member en van $member2[uid] maakt hij $member[id]
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het ging vooral om die [uid] -> [id] omdat uid niet wordt opgehaald
0
Cees

Lid · Topicstarter

Berichten
103
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoe kan ik die query dan in een variable krijgen die hij echot?
edit
Want als je hem weer in while doet komt er een fout maar kan je die query niet beter doen met LEFT JOIN ofzo?
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