TFG Posted April 16, 2008 Share Posted April 16, 2008 i need help on this, can someone please look at this, let's say there are two tables on my database 1. category table having column id with values like 1 to 10 2. details table having column category with the values like 2, 4, 6, 8, 10 so i want to list 5 values from category table's id columns but only those values that are in details table category column, how do i do it pls guide me. Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/ Share on other sites More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 u mean column id && column category are equal values write? Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518229 Share on other sites More sharing options...
TFG Posted April 16, 2008 Author Share Posted April 16, 2008 actually i mean like this there will be first table like this CREATE TABLE `category` ( `id` mediumint(9) NOT NULL auto_increment, `title` text collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=945 ; which will have like this INSERT INTO `category` (`id`, `title`) VALUES (1, 'Adriana'), (2, 'Alicia'), (3, 'Anna'), (4, 'Avril'), (5, 'Britney'), (6, 'Cameron'), (7, 'Carmen'), (8, 'Charlie'), (9, 'Charlize'), (10, 'Christina'); and there will be another table like this CREATE TABLE `details` ( `id` int(6) NOT NULL auto_increment, `category` text collate latin1_general_ci NOT NULL, `brief` text collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=6470 ; and will have like this (1, '2', 'brief of category with id 2'), (2, '4', 'brief of category with id 4'), (3, '6', 'brief of category with id 6'), (4, '8', 'brief of category with id 8'), (5, '10', 'brief of category with id 10'); and now wt i want is to list 5 categories from the category table only if those id are in details talble like category with id 2 is in details table now i want to list that not directly from the details table but from the category table if the same value exist in details table Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518236 Share on other sites More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 select id,title from category LEFT OUTER JOIN details ON category.id = details.category WHERE category.id = details.category Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518243 Share on other sites More sharing options...
TFG Posted April 16, 2008 Author Share Posted April 16, 2008 how can i do that using php ? could you please post the php codes. Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518247 Share on other sites More sharing options...
haku Posted April 16, 2008 Share Posted April 16, 2008 Its much better to do it with MYSQL. Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518250 Share on other sites More sharing options...
TFG Posted April 16, 2008 Author Share Posted April 16, 2008 i don't get it how can i do it using MYSQL i need it to be shown on my main page of a php site Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518253 Share on other sites More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 $sql=mysql_query("select category.id,category.title from category left join details on category.id=details.category "); while($res=mysql_fetch_array($sql)) {echo $res["id"]; echo $res["title"]; } Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518254 Share on other sites More sharing options...
TFG Posted April 16, 2008 Author Share Posted April 16, 2008 actually that doesn't works as i wanted what i want to do is echo the id's selecting from category table only if the id value exisits in details table Link to comment https://forums.phpfreaks.com/topic/101318-small-phpmysql-help-needed/#findComment-518271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.