リクエストに応じて情報を取得したい3つの異なるデータベースがあります。
CREATE TABLE IF NOT EXISTS `catbreeds` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`information_breed` varchar(30) NOT NULL,
`information_breed_seo` varchar(30) NOT NULL,
`information_ems` varchar(4) NOT NULL,
`information_ipaddress` text NOT NULL,
`fact_head` text NOT NULL,
`fact_ears` text NOT NULL,
`fact_eyes` text NOT NULL,
`fact_eyecolor` text NOT NULL,
`fact_body` text NOT NULL,
`fact_legs` text NOT NULL,
`fact_paws` text NOT NULL,
`fact_tail` text NOT NULL,
`fact_coat` text NOT NULL,
`fact_extra` text NOT NULL,
`date_added` datetime NOT NULL,
`date_edited` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
)
CREATE TABLE IF NOT EXISTS `catbreeds_personality` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`information_name` varchar(50) NOT NULL,
`information_name_seo` varchar(50) NOT NULL,
`information_ipaddress` text NOT NULL,
`date_added` datetime NOT NULL,
`date_edited` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
)
CREATE TABLE IF NOT EXISTS `catbreeds_personality_links` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`id_breed` int(10) DEFAULT '0',
`id_personality` int(10) DEFAULT '0',
`information_ipaddress` text NOT NULL,
`date_linked` datetime NOT NULL,
`date_edited` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
)
ソースコードでは、データベースからパーソナリティをループしcatbreeds_personality
ます。すべての性格はウェブサイトでリンクされており、各リンクをクリックすると、猫の品種のリスト(catbreeds
データベースのリストから取得)は、選択した性格の後に猫の品種を並べ替えます。
例
データベースには2つの猫の品種がありcatbreeds
ます。Burmilla
およびAbessinier
。
catbreeds_personality
データベースには4つのパーソナリティがあります。Social
、、、、および。Playful
_Active
Curious
データベースには3つのcatbreeds_personality_links
リンクされたパーソナリティがあります。Social
、、、Playful
およびCurious
。
Cursious
ウェブサイトでは、訪問者が品種のリンクをクリックすると、表示され、非Burmilla
表示にAbessinier
なります。性格Social
とPlayful
クリックすると、品種Abessinier
が表示され、他の品種が非表示になります。等々。すべてがどのように機能するかを理解していただければ幸いです。
ここでの唯一の問題は、SQLがこの場合どのように見えるかわからないことです。現時点では、私のSQLクエリは次のようになっています。
SELECT * FROM catbreeds AS cb, catbreeds_personality AS cbp, catbreeds_personality_links AS cbpl
WHERE cbp.id = '6'
AND cbpl.id_breed = cb.id
ORDER BY cb.information_breed ASC
SQLクエリは、ID番号6を持たない4つの結果を返します。
どうすればこの問題を解決できますか?
前もって感謝します。