Ik heb hieronder het volgende probleem:
een vrij makkelijke sql-query die niet werkt (dat is dus mijn probleem)
Ik heb hiervoor veel met ASP en ACCESS gewerkt, en daar lukt het wel goed.
Nu wil ik dit doen in PHP en mySQL. De syntax van "IN" geeft hier de problemen, want afzonderlijk doen ze het gewoon goed.
Weet iemand wat er fout aan is?
SELECT * FROM Topics
WHERE Forum_ID IN (SELECT Forum_ID FROM Forums WHERE Cat_ID = $Cat_ID)
$Cat_ID is bv. 1
#
# Tabel structuur voor tabel Forums
#
CREATE TABLE Forums (
Cat_ID tinyint(3) unsigned DEFAULT '0' NOT NULL,
Forum_ID tinyint(10) unsigned DEFAULT '0' NOT NULL,
F_Name varchar(100),
F_Description varchar(255),
F_Posts int(10) DEFAULT '0',
F_Replies int(10),
F_Lastpost datetime,
F_Lastposter int(10) unsigned,
F_Moderator int(10) unsigned,
F_Anoniem tinyint(3) unsigned,
F_Member tinyint(3) unsigned,
F_Jeugdleider tinyint(3) unsigned,
F_Redactie tinyint(3) unsigned,
PRIMARY KEY (Cat_ID, Forum_ID)
);
# --------------------------------------------------------
#
# Tabel structuur voor tabel Topics
#
CREATE TABLE Topics (
Topic_ID int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
Forum_ID tinyint(10) unsigned DEFAULT '0' NOT NULL,
T_Subject varchar(50) DEFAULT '0' NOT NULL,
T_Message mediumtext NOT NULL,
T_Date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
T_Views int(10) unsigned DEFAULT '0' NOT NULL,
T_Icon int(10) unsigned DEFAULT '0' NOT NULL,
T_EmailNotify tinyint(3) unsigned DEFAULT '0' NOT NULL,
T_Closed tinyint(3) unsigned DEFAULT '0' NOT NULL,
T_IP varchar(15) DEFAULT '0' NOT NULL,
T_ShowSig tinyint(3) unsigned DEFAULT '0' NOT NULL,
T_Poster int(10) unsigned DEFAULT '0' NOT NULL,
T_Lastpost datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
T_Replies int(10) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (Topic_ID),
KEY Topic_ID (Topic_ID)
);
een vrij makkelijke sql-query die niet werkt (dat is dus mijn probleem)
Ik heb hiervoor veel met ASP en ACCESS gewerkt, en daar lukt het wel goed.
Nu wil ik dit doen in PHP en mySQL. De syntax van "IN" geeft hier de problemen, want afzonderlijk doen ze het gewoon goed.
Weet iemand wat er fout aan is?
SELECT * FROM Topics
WHERE Forum_ID IN (SELECT Forum_ID FROM Forums WHERE Cat_ID = $Cat_ID)
$Cat_ID is bv. 1
#
# Tabel structuur voor tabel Forums
#
CREATE TABLE Forums (
Cat_ID tinyint(3) unsigned DEFAULT '0' NOT NULL,
Forum_ID tinyint(10) unsigned DEFAULT '0' NOT NULL,
F_Name varchar(100),
F_Description varchar(255),
F_Posts int(10) DEFAULT '0',
F_Replies int(10),
F_Lastpost datetime,
F_Lastposter int(10) unsigned,
F_Moderator int(10) unsigned,
F_Anoniem tinyint(3) unsigned,
F_Member tinyint(3) unsigned,
F_Jeugdleider tinyint(3) unsigned,
F_Redactie tinyint(3) unsigned,
PRIMARY KEY (Cat_ID, Forum_ID)
);
# --------------------------------------------------------
#
# Tabel structuur voor tabel Topics
#
CREATE TABLE Topics (
Topic_ID int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
Forum_ID tinyint(10) unsigned DEFAULT '0' NOT NULL,
T_Subject varchar(50) DEFAULT '0' NOT NULL,
T_Message mediumtext NOT NULL,
T_Date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
T_Views int(10) unsigned DEFAULT '0' NOT NULL,
T_Icon int(10) unsigned DEFAULT '0' NOT NULL,
T_EmailNotify tinyint(3) unsigned DEFAULT '0' NOT NULL,
T_Closed tinyint(3) unsigned DEFAULT '0' NOT NULL,
T_IP varchar(15) DEFAULT '0' NOT NULL,
T_ShowSig tinyint(3) unsigned DEFAULT '0' NOT NULL,
T_Poster int(10) unsigned DEFAULT '0' NOT NULL,
T_Lastpost datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
T_Replies int(10) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (Topic_ID),
KEY Topic_ID (Topic_ID)
);