SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Nov 22, 2004, 20:58 #1
- Join Date
- Nov 2004
- Location
- tn
- Posts
- 60
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Repost.. [EDIT: I've Done It!!]
I posted this the other day, and while someone was kind enough to hang with me for about 12 hours and try to get it to work, it didn't. So I want to try again but hear me out.. the methods that were being sent to me weren't quite the method I figured to be easiest. Although I am the new guy. Please bear with me, getting the forums function is my main goal, as it is the basis of the site. Anyway, here goes: (I apologize in advance for whatever headaches I may cause)
Ok. I'm trying to make some halfway functional forums. Now, I have the catagories in the database, and pulling from it in my forum.php. What I want, is for the user to click the category name, and it goes to forums2.php and drops down and lists the forums in whatever category they clicked. I assumed it would use this:
Code:<a href="forums2.php?cat_id=<? echo $cat_id ?>
forums.php works fine. I imagine forum2 would just be an altered version of this one, so that when it pulls the category thats sent through the url (with cat_id), it will also list the forums that are associated with it and list them.
table "categories":
cat_id......cat_title.......cat_order
..1............blah............10
table "forums"-- sub category
forum_id......cat_id.....forum_name....forum_order
..1..............1.........blah...........10
.................^This is how the forums associate with parent cat.
Here is my code for forums.php:
Code:<TABLE WIDTH="100%" border="1" CELLSPACING="0" CELLPADDING="3" bgcolor="#D4D8D6"> <TR ALIGN="left"> <TD WIDTH="2%" CLASS="boardheading" Background="images/top.gif">+ <TD WIDTH="73%" CLASS="boardheading" ALIGN="center" Background="images/top.gif">Category Titles <TD WIDTH="5%" CLASS="boardheading" ALIGN="center" Background="images/top.gif">Topics <TD WIDTH="5%" CLASS="boardheading" ALIGN="center" Background="images/top.gif">Posts <TD WIDTH="15%" CLASS="boardheading" ALIGN="center" Background="images/top.gif">Last post </tr> <?php require 'db_connect.php'; $query="SELECT * FROM categories ORDER BY cat_order ASC"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if ($num==0) { echo "No Entries."; } else { if ($num>25) { $to=25; }else{ $to=$num; } } $i=0; while ($i < $to) { $cat_id=mysql_result($result,$i,"cat_id"); $cat_title=mysql_result($result,$i,"cat_title"); ?> <TR ALIGN="left"> <TD><a href="forums2.php?cat_id=<? echo $cat_id ?>" style="color:#333333;">+</a><TD><a href="forums2.php?cat_id=<? echo $cat_id ?>" style="color:#333333;"><? echo $cat_title ?></a><TD>10<TD>100<TD>Phases <? $i++; } echo "<TR ALIGN='left'> <TR> </TABLE>"; ?>
Last edited by Phases; Nov 23, 2004 at 04:33.
-
Nov 22, 2004, 23:58 #2
- Join Date
- Nov 2004
- Location
- tn
- Posts
- 60
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok here's what I'm thinking..
I have it now to where it gets that variable that is sent and calls it $cid.
Now, considering this portion of the code:
Code:if ($num>25) { $to=25; }else{ $to=$num; } } $i=0; while ($i < $to) { $cat_id=mysql_result($result,$i,"cat_id"); $cat_title=mysql_result($result,$i,"cat_title"); ?> <TR ALIGN="left"> <TD><a href="forums2.php?cat_id=<? echo $cat_id ?>" style="color:#333333;">+</a> <TD><a href="forums2.php?cat_id=<? echo $cat_id ?>" style="color:#333333;"><? echo $cat_title ?></a> <TD>10 <TD>100 <TD>Phases <? $i++; } echo "<TR ALIGN='left'> <TR> </TABLE>"; ?>
and then again after the <TD> where the $i++ is, tell it the same thing. (the first one just accounts for the top category it spits out, right?
EDIT: or what about on the query line itself? Can I have it query categories to list, and also to query forums for the cata.... hey wait. I gotta query forums at some point for this to work at all anyway, right?
-
Nov 23, 2004, 00:43 #3
- Join Date
- Nov 2004
- Location
- tn
- Posts
- 60
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Methinks the answer lies in the query line.. something about select/join/where...
Everyones given up on phases?
-
Nov 23, 2004, 01:26 #4
- Join Date
- Nov 2004
- Location
- tn
- Posts
- 60
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok ok, I'm getting there! Just a little help needed.. follow me here!
Forum.php someone sees a list of categories. They click one. They go to forum2.php. It loads the same thing, except whichever one they clicked on "opens up" and drops down to show the sub categories.
Now, I've got forum2.php to where it pulls in the variable you send through the url by clicking the link and calls it $cid.
I've got it to where it pulls in the data from the "forums" table based on that $cid.
I've got it to where it lists the categories as it should, and in the "last post by" colum, it lists the subcategories it pulled from "forums" as it should, put it there for testing.
NOW, what I need is for those forums names to go under the categorie that was clicked on to begin with.. but I'm not sure how to set that loop up.
I beg of you, I'm so close!
Here is the website. You are going to see errors because you are not logged in, at the top of the page. Nevermind those. You'll also see some that show after the forums run out of things to say, but there are still categories listed. You'll see what I mean
Click here, then pick a category, click it, to see what it does: (I suggest movies, to be error free.. same number of rows needed)
http://phases-online.com/phases78/forums/forums.php
here is my code to forums2.php: (the part we're concerned with anyway)
Code:<?php require 'db_connect.php'; $cid = $HTTP_GET_VARS['cat_id']; $query="SELECT * FROM categories ORDER BY cat_order ASC"; $result=mysql_query($query); $num=mysql_numrows($result); $query2="SELECT * FROM forums WHERE cat_id=$cid ORDER BY forum_order ASC"; $result2=mysql_query($query2); $num2=mysql_numrows($result2); mysql_close(); if ($num==0) { echo "No Entries."; } else { if ($num>25) { $to=25; }else{ $to=$num; } } $i=0; while ($i < $to) { $cat_id=mysql_result($result,$i,"cat_id"); $cat_title=mysql_result($result,$i,"cat_title"); $forum_id=mysql_result($result2,$i,"forum_id"); $forum_name=mysql_result($result2,$i,"forum_name"); ?> <TR ALIGN="left"> <TD><a href="forums2.php?cat_id=<? echo $cat_id ?>" style="color:#333333;">+</a> <TD><a href="forums2.php?cat_id=<? echo $cat_id ?>" style="color:#333333;"><? echo $cat_title ?></a> <TD>10 <TD>100 <TD><? echo $forum_name ?> <? $i++; } echo "<TR ALIGN='left'> <TR> </TABLE>"; ?>
-
Nov 23, 2004, 04:29 #5
- Join Date
- Nov 2004
- Location
- tn
- Posts
- 60
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Holy whack. I've done it.
Finally!
/celebrates
-
Nov 23, 2004, 05:24 #6
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Congratulations Phases, ain't it great when something works!
(It did appear you were taking to yourself for a while there!)Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
Bookmarks