Forum Moderators: coopster
I'm simply trying to associate links with link categories for output. I know I need to join the two tables (links and linkcats) but I'm unsure exactly how and I'm having trouble grasping the concept (and yes, I've read a ton of tutorials and the mysql manual to no avail) Can someone offer a practical example on how I could SELECT the data from the two tables for output something like:
$linktext ($linkcat): <a href="delete.php?id=$linkid">delete</a>
for example, where $linkcat 1 is "search engines" and 2 is "government":
Google (1): <a>delete</a>
White House (2): <a>delete</a>
Yahoo (1): <a>delete</a>
etc..
Here's my db:
mySQL:
-- Table structure for table `linkcats`
--
CREATE TABLE `linkcats` (
`linkcat` int(11) NOT NULL auto_increment, //category id #
`linkcattext` varchar(255) default NULL, //title of category
PRIMARY KEY (`linkcat`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `links`
--
CREATE TABLE `links` (
`linkid` int(11) NOT NULL auto_increment, //link id #
`linkcat` int(11) NOT NULL, //associated category id #
`linktext` varchar(255) default NULL, //title of link
`linkurl` varchar(255) default NULL, //url of link
PRIMARY KEY (`linkid`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
Hope that all makes sense. Thanks in advance!
rk
Should I just be able to reuse that same select in my form and loop it into a dropdown?
Thanks so much for your help, I've been chewing on joins for too long now :)
Cheers,
rk
I've come across another problem though. When I got to output my list of links, I can easily dump it all out in a nice ordered list or whatever I might need, but I'm unsure how to flag and sort the links by category (preferably with a header)? I know there's sql to do it but I'm clueless. Can someone point out a method of breaking up all the links by link category for output? ie,
CATEGORY 1
Link 1
Link 2
CATEGORY 2
Link 3
Link 4
etc..
Any help would be appreciated.
Regards,
rk