SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: category help
-
May 3, 2003, 04:02 #1
- Join Date
- Jun 2001
- Location
- Australia
- Posts
- 676
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
category help
Hi,
I need to add this type of system to my script.
Home > $category1 > $category2 > $threadID
So the parentid in $category2 = $category1 and the the formid in $threadID = $category2 and so on.
Can anyone give me an example of how this works?
-
May 3, 2003, 18:37 #2
- Join Date
- May 2001
- Location
- Vancouver, BC Canada
- Posts
- 502
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
make three seperate tables.
category1, category2 and threads
category1 would contain a unique id and name and other things you might want to add to it.
category2 containts a uniqueid, category1id, name...etc
thread would contain a uniqueid, category2id, name...etc.
then to call and display it, just query the thread, then grab the category2 id and name from the thread query, and then grab the category1 id and name from the category2 query.
another way is to use the JOIN parameter in mysql., where instead of having to do three seperate queries, you can do one query. and the thread table would contain a unique id, cat1 id, and cat2 id.
e.g.PHP Code:$sql = ("select * from thread, category1, category2 WHERE thread.category1=category2.id AND category2.category1=category1.id ")
or die(mysql_error());
-
May 3, 2003, 19:23 #3
- Join Date
- Jun 2001
- Location
- Australia
- Posts
- 676
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I should have explained myself better, excuse me for not doing that.
Say I have 3 categories and I click on Category1 it would display
Home > Category1
Now, there category2 is inside Cateogry1, so it will display after I click Category2 link.
Home > Category1 > Category2
And finally getting the news thread name.
Home > Category1 > Category2 > threadname
Somewhat like sitepoints system.
SitePoint Community Forums / Program Your Site / PHP / category help
I started to write somme code, but I lost my way for the thread name.
PHP Code:function convert_id_to_cat($el){
$tmp_query = mysql_query("select cattitle from forum_category where fid='$el'");
$tmp_data = mysql_fetch_array($tmp_query);
return $tmp_data[cattitle];
}
function make_location($el){
$path_array[] = "<font face='arial' size='2' color='#3333CC'> > <b> ".convert_id_to_cat($el)."</b> </font>";
$this_category = $el; $parents_left = true;
while($parents_left){
$tmp_query = mysql_query("select parentid from forum_category where fid='$this_category'");
$tmp_data = mysql_fetch_array($tmp_query);
if($tmp_data[parent_id]>0) {
$path_array[] = "<font face='arial' size='2' color='#3333CC'> > <a href="cat.php?fid=".$tmp_data[parentid].""><b><font color='#3333CC'>".convert_id_to_cat($tmp_data[parent_id])."</font></b></a></font>";
$this_category = $tmp_data[parentid];
}
else $parents_left = false;
}
$path_array[] = "<font size='4' face='arial'><b>$thecatname</b></font><font face='arial' size='2'><a href="$homepage"><b><font color='#3333CC'>Index</font></b></a></font>";
$correct_order = @array_reverse($path_array);
$cat_location = @implode("", $correct_order);
return $cat_location;
}
echo "<table width='750' align='center' border='0' bgcolor='#E7EBFE' cellspacing='0' cellpadding='5'><tr>";
$cat_id2 = $fid;
$you_are_here = make_location($fid);
echo "<td><font size='2' face='arial'>".$you_are_here."</font></td></tr></table>";
-
May 4, 2003, 03:15 #4
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe try a search here at sitepoint ? This has been discussed before 8)
As for script, I've yet to implement something like this 8(
-
May 4, 2003, 05:57 #5
- Join Date
- Jun 2001
- Location
- Australia
- Posts
- 676
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Dr Livingston,
I tried to do a search but had no luck, maybe im not using the right search word. any ideas?
-
May 4, 2003, 06:02 #6
- Join Date
- Mar 2001
- Location
- Philadelphia, US
- Posts
- 2,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
"Breadcrumbs" is the word you're looking for. There's quite a few discussions on the topic that you should find useful.
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
-
May 4, 2003, 07:04 #7
- Join Date
- Jun 2001
- Location
- Australia
- Posts
- 676
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's cool, I found a solution with my code. Thanks guys.
-
May 4, 2003, 08:26 #8
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You couldn't post it here for all to see and use ? LoL...
-
May 4, 2003, 09:08 #9
- Join Date
- Jun 2001
- Location
- Australia
- Posts
- 676
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Dr Livingston
PHP Code:
function convert_id_to_cat($el){
$tmp_query = mysql_query("select cattitle from forum_category where fid='$el'");
$tmp_data = mysql_fetch_array($tmp_query);
return $tmp_data[cattitle];
}
function make_location($el){
$path_array[] = " > <a href="cat.php?fid=$el"><b>".convert_id_to_cat($el)."</b></a>";
$this_category = $el; $parents_left = true;
while($parents_left){
$tmp_query = mysql_query("select parentid from forum_category where fid='$this_category'");
$tmp_data = mysql_fetch_array($tmp_query);
if($tmp_data[parentid]>0) {
$path_array[] = " > <a href="cat.php?fid=".$tmp_data[parentid].""><b>".convert_id_to_cat($tmp_data[parentid])."</b></a>";
$this_category = $tmp_data[parentid];
}
else $parents_left = false;
}
$path_array[] = "<a href="$homepage"><b>Index</b></a>";
$correct_order = @array_reverse($path_array);
$cat_location = @implode("", $correct_order);
return $cat_location;
}
echo "<table width='750' align='center' border='0' bgcolor='#E7EBFE' cellspacing='0' cellpadding='5'><tr>";
$you_are_here = make_location($fid);
echo "<td><font size='2' face='arial' color='#3333CC'>".$you_are_here."";
// ==== START: NEW CODE ====
$sql = mysql_fetch_array(mysql_query("SELECT title FROM forum_threads WHERE forumid='$fid'"));
$title = $sql["title"];
if($threadid==""){ $threadtitle= "";} else { $threadtitle = " > $title";}
// ==== END: NEW CODE ====
echo "$threadtitle</font></td></tr></table>";
Bookmarks