I have 3 different databases which I want to get information from upon request.
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`)
)
In the source code, I loop the personalities from the catbreeds_personality database. Every personality are linked on the website and when I click on each of the links, the list with catbreeds (fetched from the list in the catbreeds database) will be sorting the cat breeds after the personalities I have chosen.
Example
There is 2 cat breeds in the catbreeds database; Burmilla and Abessinier.
The catbreeds_personality database has 4 personalities; Social, Playful, Active, and Curious.
The catbreeds_personality_links database has 3 linked personalities; Social, Playful, and Curious.
On the website, when the visitor clicks on the link for Cursious the breed Burmilla will show and Abessinier will hide. If the personality Social and Playful are clicked, the breed Abessinier will show and the other breed will hide. And so on. I hope you’re getting how it all will work.
The only problem here is that I don’t know how the SQL looks like for this. At the moment my SQL query looks like this:
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
The SQL query returns 4 results which doesn’t even have the ID number 6.
How can I solve this problem?
Thanks in advance.
1 Answer