fixxxer Posted March 29, 2007 Share Posted March 29, 2007 This may sound like a stupid query and ive looked on the net for a tutorial. im trying to build a site that contains information stored in categories. to give an example if i wanted to store information about football i would want a structure like this Football > English > Premiership > Liverpool > Steven Gerrard > the problem im having is how do i store this in a database that links it all together i have an idea on how i can do it but it seems long winded and stupid, basically i want each category to be a link to that section so if they clicked liverpool thet would go to one page and if they clicked the parent category it would be another page. i know this might seem a simple one and im not to bad with php coding would just like an explantion of the most efficent way to do this. if anyone can help id be grateful. thanks Link to comment https://forums.phpfreaks.com/topic/44765-category-structure/ Share on other sites More sharing options...
fixxxer Posted March 29, 2007 Author Share Posted March 29, 2007 can someone please help me, its not even the code im looking for just an explanation of the osrt of set up i need e.g database and how i link the different catergories so far ive got :- cat_id parent_id cat_name where i can put the parent id and so can create the breadcrumbs by going back through the db but this seemed quite long winded. can someone suggest to me the best way to do this thanks Link to comment https://forums.phpfreaks.com/topic/44765-category-structure/#findComment-217371 Share on other sites More sharing options...
komquat Posted March 29, 2007 Share Posted March 29, 2007 What you want to do is find a website that helps with Database set-up. you want to set up reference tables for each catergory: Example: refsports reflocation Then fill these with an unique id and then the information needed. Then in your data table you want to call these using the unique id from each reference table. Link to comment https://forums.phpfreaks.com/topic/44765-category-structure/#findComment-217384 Share on other sites More sharing options...
fixxxer Posted March 30, 2007 Author Share Posted March 30, 2007 thanks i think i get what you mean, ill give it a try. thanks again, this is the only php site where people actually seem to answer questions. thanks Link to comment https://forums.phpfreaks.com/topic/44765-category-structure/#findComment-218339 Share on other sites More sharing options...
Barand Posted March 31, 2007 Share Posted March 31, 2007 Try this Create some test data first <?php $sql = "create table sports ( id int not null primary key, parent int, name varchar (30) )"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); $sql = "INSERT INTO sports (id, parent, name) VALUES (1, 0, 'Football'), (2, 1, 'England'), (3, 2, 'Premiership'), (4, 3, 'Man U'), (5, 4, 'R Giggs'), (6, 0, 'Rugby'), (7, 6, 'England'), (8, 7, 'Div1'), (9, 8, 'Sale'), (10, 9, 'J Robinson'), (11, 4, 'G Nevill'), (12, 3, 'Chelsea'), (13, 12, 'T Henri')"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); ?> Then <?php $sql = "SELECT * FROM sports"; $g = new baaGrid($sql); $g->display(); function crumbs($id, $level=0) { $sql = "SELECT parent, name FROM sports WHERE id = $id"; $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); list ($p, $n) = mysql_fetch_row($res); if ($p != 0) crumbs($p, $level+1); echo ($p==0) ? "$n " : "» $n "; } crumbs(3); // --> Football » England » Premiership echo '<br>'; crumbs(10); // --> Rugby » England » Div1 » Sale » J Robinson echo '<br>'; crumbs(5); // --> Football » England » Premiership » Man U » R Giggs echo '<br>'; ?> Link to comment https://forums.phpfreaks.com/topic/44765-category-structure/#findComment-218572 Share on other sites More sharing options...
monkeymajik Posted July 7, 2011 Share Posted July 7, 2011 Hi, i have trouble to printing breadcrumb from one table that have id and parent id. since i can't explode from URL. Any suggestion ? Link to comment https://forums.phpfreaks.com/topic/44765-category-structure/#findComment-1239472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.