birk
08-03-2006, 08:38 PM
I'll try to explain this the best I can. Hopefully there are some people out there that can help me with this one since I am completely lost. :confused:
First some information. I have two tables with this structure:
--
-- Struktur-dump for tabellen `sl_shares`
--
CREATE TABLE `sl_shares` (
`rel_id` int(10) unsigned NOT NULL auto_increment,
`req_counter` int(10) unsigned NOT NULL default '0',
`dl_counter` int(10) unsigned NOT NULL default '0',
`req_state` int(10) unsigned default NULL,
`req_userid` int(10) unsigned default NULL,
`rel_userid` int(10) unsigned default NULL,
`notmine` tinyint(4) NOT NULL default '0',
`reqrel_date` int(10) unsigned default '0',
`cat_id` mediumint(10) unsigned default NULL,
`description` text,
`comments` text,
`website_url` text,
`network` tinyint(3) unsigned default '1',
`email_notify` tinyint(3) unsigned NOT NULL default '0',
`anonymous` tinyint(3) unsigned default '0',
`str_full` varchar(255) default NULL,
`str_short` varchar(255) default NULL,
`str_search` varchar(255) default NULL,
`releasever` text,
`releasename` text,
`publisher` text,
`users_ip` varchar(23) default NULL,
`tracked` tinyint(3) unsigned default '1',
PRIMARY KEY (`rel_id`),
KEY `rel_id` (`rel_id`,`req_userid`,`rel_userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Full list of releases and requests';
--
-- Struktur-dump for tabellen `sl_tag_data`
--
CREATE TABLE `sl_tag_data` (
`data_id` bigint(20) unsigned NOT NULL auto_increment,
`rel_id` int(10) unsigned default NULL,
`tag_id` int(10) unsigned NOT NULL default '0',
`data` varchar(200) default NULL,
PRIMARY KEY (`data_id`),
KEY `rel_id` (`rel_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Associated data for the tags';
What I want to accomplish is get the right data out of the sl_shares table to use in an rss feed I want to create. I'll try to make an example of the problem here based on the entires in both tables for the latest test release I have made.
INSERT INTO `sl_shares` VALUES (1488, 0, 0, 2, NULL, 53568, 0, 1154347955, 1, 'sagagadfgadfgadfg', 'No comments were given for this item.', '', 1, 0, 0, 'Tester', 'Tester', 'Tester', NULL, NULL, NULL, '0.0.0.0', 1);
INSERT INTO `sl_tag_data` VALUES (6055, 1488, 10, '1');
INSERT INTO `sl_tag_data` VALUES (6054, 1488, 8, '1');
INSERT INTO `sl_tag_data` VALUES (6053, 1488, 3, '1');
INSERT INTO `sl_tag_data` VALUES (6052, 1488, 1, 'Tester');
Now this is my problem. I want to choose some information from the sl_shares table if tag_id = 10 and data = 1 and ofcause when the rel_id matches the rel_id from the sl_shares table. As I see the problem it is that there are more than one row with the same rel_id in the sl_tag_data table based on the rel_id from the sl_shares table. I have tried with some joins but I just can not seem to get it to work. The code below is what I have tried to come up with:
$test = mysql_query("SELECT DISTINCT reqrel_date, rel_id, str_full, description FROM " . $dbprefix . "shares INNER JOIN " . $dbprefix . "tag_data ON sl_shares.rel_id=sl_tag_data.rel_id WHERE sl_tag_data.tag_id=10 AND sl_tag_data.data=1 LIMIT 10");
This just returns false. Can someone please help me out? :)
First some information. I have two tables with this structure:
--
-- Struktur-dump for tabellen `sl_shares`
--
CREATE TABLE `sl_shares` (
`rel_id` int(10) unsigned NOT NULL auto_increment,
`req_counter` int(10) unsigned NOT NULL default '0',
`dl_counter` int(10) unsigned NOT NULL default '0',
`req_state` int(10) unsigned default NULL,
`req_userid` int(10) unsigned default NULL,
`rel_userid` int(10) unsigned default NULL,
`notmine` tinyint(4) NOT NULL default '0',
`reqrel_date` int(10) unsigned default '0',
`cat_id` mediumint(10) unsigned default NULL,
`description` text,
`comments` text,
`website_url` text,
`network` tinyint(3) unsigned default '1',
`email_notify` tinyint(3) unsigned NOT NULL default '0',
`anonymous` tinyint(3) unsigned default '0',
`str_full` varchar(255) default NULL,
`str_short` varchar(255) default NULL,
`str_search` varchar(255) default NULL,
`releasever` text,
`releasename` text,
`publisher` text,
`users_ip` varchar(23) default NULL,
`tracked` tinyint(3) unsigned default '1',
PRIMARY KEY (`rel_id`),
KEY `rel_id` (`rel_id`,`req_userid`,`rel_userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Full list of releases and requests';
--
-- Struktur-dump for tabellen `sl_tag_data`
--
CREATE TABLE `sl_tag_data` (
`data_id` bigint(20) unsigned NOT NULL auto_increment,
`rel_id` int(10) unsigned default NULL,
`tag_id` int(10) unsigned NOT NULL default '0',
`data` varchar(200) default NULL,
PRIMARY KEY (`data_id`),
KEY `rel_id` (`rel_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Associated data for the tags';
What I want to accomplish is get the right data out of the sl_shares table to use in an rss feed I want to create. I'll try to make an example of the problem here based on the entires in both tables for the latest test release I have made.
INSERT INTO `sl_shares` VALUES (1488, 0, 0, 2, NULL, 53568, 0, 1154347955, 1, 'sagagadfgadfgadfg', 'No comments were given for this item.', '', 1, 0, 0, 'Tester', 'Tester', 'Tester', NULL, NULL, NULL, '0.0.0.0', 1);
INSERT INTO `sl_tag_data` VALUES (6055, 1488, 10, '1');
INSERT INTO `sl_tag_data` VALUES (6054, 1488, 8, '1');
INSERT INTO `sl_tag_data` VALUES (6053, 1488, 3, '1');
INSERT INTO `sl_tag_data` VALUES (6052, 1488, 1, 'Tester');
Now this is my problem. I want to choose some information from the sl_shares table if tag_id = 10 and data = 1 and ofcause when the rel_id matches the rel_id from the sl_shares table. As I see the problem it is that there are more than one row with the same rel_id in the sl_tag_data table based on the rel_id from the sl_shares table. I have tried with some joins but I just can not seem to get it to work. The code below is what I have tried to come up with:
$test = mysql_query("SELECT DISTINCT reqrel_date, rel_id, str_full, description FROM " . $dbprefix . "shares INNER JOIN " . $dbprefix . "tag_data ON sl_shares.rel_id=sl_tag_data.rel_id WHERE sl_tag_data.tag_id=10 AND sl_tag_data.data=1 LIMIT 10");
This just returns false. Can someone please help me out? :)