SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 32
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I get a push in the right direction please?

    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 drops down and lists the forums in that category. I assumed it would use this

    Code:
    <a href="forums2.php?cat_id=<? echo $cat_id ?>
    so I already put it in, as you can see. Yes, on the database the forums have what category id they are assigned to.

    If you need a visual of what I'm talking about, here's a pic (of what's output'd from the code below):

    here

    Any push to how to do this would be greatly appreciated. Thanks fellas

    (sorry its a mess, I'm learning)

    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>";
    
    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    explain what u want better please couse i dont understand
    but u have some errors...

    wrong...
    $num=mysql_numrows($result);

    right...
    $num=mysql_num_rows($result);

    cheers

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok look at the picture. Those are categories. Now, within those catagories I have forums.. or subcategories. Right now the categories you see are "closed". What I want is to be able to click the plus sign to the left, and it drops down that category and lists the sub categories that are within it.

    I realize this is a tough one to grasp because it seems so vage and there are so many variables unanswered for you guys.

    Categories are being pulled from one table right now using cat_id. The sub categories under them are in a different table, "forums", with their own forum_id, but also each is assigned a number to which cat_id it is to go under.

    Kinda hard to explain...

  4. #4
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Phases
    Ok look at the picture. Those are categories. Now, within those catagories I have forums.. or subcategories. Right now the categories you see are "closed". What I want is to be able to click the plus sign to the left, and it drops down that category and lists the sub categories that are within it.

    I realize this is a tough one to grasp because it seems so vage and there are so many variables unanswered for you guys.

    Categories are being pulled from one table right now using cat_id. The sub categories under them are in a different table, "forums", with their own forum_id, but also each is assigned a number to which cat_id it is to go under.

    Kinda hard to explain...
    keep in mind page has to reload completely at every click... Now I don't like to say this but I guess javascript is better for such things.
    I have programmed a tree fold-out, like you want, and it's quit a lot of code for such a small "feature".
    code below does this and in extra makes a button with GD-libraries, but you can strip that part if you like.

    PHP Code:
    <?php
    /////////////////////////////////////////////////////////////////
     //init
     
    $hn=$_GET[hn];
     if(
    $hn)
     {
      
    $sn=$_GET[sn];
      if(!
    $sn)
      {
       
    $vraag="SELECT id FROM navigatie_sub WHERE hoofd='".$hn."' ORDER BY id LIMIT 1";
       
    $ok=mysql_query($vraag);
       if(!
    $ok)
       {die(
    'MySQL error'.mysql_error().'<br>');}
       
    $rij=mysql_fetch_array($ok);
       
    $sn=$rij[id];
      }
     }
    /////////////////////////////////////////////////////////////////
     //font
     
    $fontdir='/home/camping/public_html/fonts';
     
    $ttf='arialbd.ttf';
     
    $font=$fontdir."/".$ttf;
     
    $fontsize=10;
    /////////////////////////////////////////////////////////////////
     
    $navigation="<table width='100%' border='0' cellpadding='0' cellspacing='3'>\n";
    /////////////////////////////////////////////////////////////////
     //hoofdnav knoppen aanmaken
     
    $image_size=getimagesize("./pics/nav/knop.jpg");
     
    $breedte=$image_size[0];
     
    $hoogte=$image_size[1];
     
    $vraag="SELECT * FROM navigatie_hoofd WHERE id>1 ORDER BY id";
     
    $ok=mysql_query($vraag);
     if(!
    $ok)
     {die(
    'MySQL error'.mysql_error().'<br>');}
     
    $counter='1';
     while(
    $rij=mysql_fetch_array($ok))
     {
      
    $navigation.="<tr><td>";
      
    //dummy knop aanmaken voor color allocation te doen werken
      
    $im=imagecreate($breedte,$hoogte);
      
    //colorallocation
      
    $color=imagecolorallocate($im100100100); //donkergrijs
      
    $knop=imagecreatefromjpeg("./pics/nav/knop.jpg");
      
    $hoek=0;
      
    imagecopy($im,$knop,0,0,0,0,$breedte,$hoogte);
      
    imagedestroy($knop);
      
    //midden bepalen
      
    $picwidth=imagesx($im);
      
    $picheight=imagesy($im);
      list(
    $pos_blx$pos_bly$pos_brx$pos_bry$pos_trx$pos_try$pos_tlx$pos_tly)=imagettfbbox($fontsize$hoek$font$rij[naam]);
      
    $textwidth $pos_brx $pos_blx;
      
    $textheight $pos_bly $pos_tly;
      
    $start_x = (($picwidth $textwidth) / 2) + 0;
      
    $start_y = (($picheight $textheight) / 2) + $textheight 0;
      
    imagettftext($im$fontsize$hoek$start_x$start_y$color$font$rij[naam]);
      
    imagejpeg($im"./pics/nav/knop".$rij[href].".jpg"100);
      
    //speciale href wanneer "Begin knop wordt aangemaakt"
      
    if($rij[href]=='index')
      {
       
    $navigation.="<a href='index.php'><img src='./pics/nav/knop".$rij[href].".jpg' border='0'></a></td>";
      }
      else
      {
       
    $navigation.="<a href='content.php?hn=$rij[id]'><img src='./pics/nav/knop".$rij[href].".jpg' border='0'></a></td>";
      }
      
    imagedestroy($im);
      
    //Zien of er subnavknoppen moeten aangemaakt worden. Zoja doen.
      
    if($hn == $rij[id])
      {
       
    //subnav knoppen aanmaken
       
    $image_size=getimagesize("./pics/nav/knop.jpg");
       
    $breedte=$image_size[0];
       
    $hoogte=$image_size[1];
       
    $vraag2="SELECT * FROM navigatie_sub WHERE hoofd=$rij[id] ORDER BY id";
       
    $ok2=mysql_query($vraag2);
       if(!
    $ok2)
       {die(
    'MySQL error'.mysql_error().'<br>');}
       
    $counter2='1';
       while(
    $rij2=mysql_fetch_array($ok2))
       {
        if(
    $counter2!='1')$navigation.="<tr><td></td>";
        
    $navigation.="<td>";
        
    //dummy knop aanmaken voor color allocation te doen werken
        
    $im=imagecreate($breedte,$hoogte);
        
    //colorallocation
        
    $color=imagecolorallocate($im100100100); //wit
        
    $knop=imagecreatefromjpeg("./pics/nav/knop.jpg");
        
    $hoek=0;
        
    imagecopy($im,$knop,0,0,0,0,$breedte,$hoogte);
        
    imagedestroy($knop);
        
    //midden bepalen
        
    $picwidth=imagesx($im);
        
    $picheight=imagesy($im);
        list(
    $pos_blx$pos_bly$pos_brx$pos_bry$pos_trx$pos_try$pos_tlx$pos_tly)=imagettfbbox($fontsize$hoek$font$rij2[naam]);
        
    $textwidth $pos_brx $pos_blx;
        
    $textheight $pos_bly $pos_tly;
        
    $start_x = (($picwidth $textwidth) / 2) + 0;
        
    $start_y = (($picheight $textheight) / 2) + $textheight 0;
        
    imagettftext($im$fontsize$hoek$start_x$start_y$color$font$rij2[naam]);
        
    imagejpeg($im"./pics/nav/sub/knop".$rij2[href].".jpg"100);
        
    $navigation.="<a href='content.php?hn=$rij[id]&sn=$rij2[id]'><img src='./pics/nav/sub/knop".$rij2[href].".jpg' border='0'></a></td></tr>";
        
    imagedestroy($im);
        
    $counter2++;
       }
      }
      
    $navigation.="</tr>";
      
    $counter++;
     }
     
    $navigation.="</table>";
    /////////////////////////////////////////////////////////////////
     //en alles weergeven
     
    echo($navigation);
    ?>
    As you can see (or not) variables and comment are in dutch, and no I didn't feel like translating it all, but if you have any questions on the code just ask

    To get you starting my $hn is your $cat_id

    And I have used different tables one for head navigation (your categories) and then one for subnavigation (your forums)

    greetz,
    koen
    The Path of excess leeds to the tower of wisdom (W. Blake)

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    practicaly u want a shortcut to categories and subcategories that comes out in an array!
    i guess u have a field into subcategorie fields which is linked to category id....
    PHP Code:
    $query mysql_query("SELECT * 
                          FROM forum_cat
                          ORDER BY id DESC"
    );
    while(
    $row mysql_fetch_array($query)) {
    $cat_id $row[0]; // where row 0 is cat id
    echo "<a href='forum.php?id='".$cat_id."'><b>".$row[1]."</b></a><br>"// where row 1 is cat name
    $ret mysql_query("SELECT *
                        FROM forum_sub_cat
                        WHERE cat = '
    $cat_id'
                        ORDER BY id DESC"
    ); // cat is a field which is linked with cat id
    $r mysql_num_rows($ret);
    for(
    $j 0$j $r; ++$j) {
    $row mysql_fetch_row($ret);
    echo 
    "&nbsp;&nbsp;<a href='forum.php?sub_id='".$row[0]."'>".$row[1]."</a><br>";
    }

    cheers
    Last edited by reminder; Nov 21, 2004 at 07:55.

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Holy whack! I just blew a blood vessel or fifty in my head trying to figure out where to substitute my own things in, on both of those codes

    Thanks for the help, I'm gunna keep working with em and see if I can get one of them to work. lol

    (yeah, phases is the new guy )

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pom, what is $sn?

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dont use pom script if u juststarted with php and if u dont know menage the get method!

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm just started.. poms script is blowing my mind, but I couldn't get yours to work either..

    I think it was the
    Code:
    $cat_id = $row[0]; // where row 0 is cat id
    .. I didn't know what you meant..

  10. #10
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what mySQL is lookin like:

    table "categories":
    cat_id.....cat_title.....cat_order
    1 ...........blah.........10


    table "forums:" <-- (sub categories)
    forum_id.......cat_id.......forum_name........forum_order
    1.................1................blahblah............10
    .....................^the cat it goes under

    the ***_order colums are in increments of ten, so I can chose what order they are in, and have room to add more.

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    row 0 is the first field into your category database table!
    so it means that that is id...
    and cat_id is the varable which contain that id couse we call it twice since this variable is stored into subcategories field to link with category field!

  12. #12
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok here is what I'm at with your code:

    Code:
    <?php
    
    require 'db_connect.php';
    
    $query = mysql_query("SELECT * 
                          FROM categories 
                          ORDER BY order_id ASC"); 
    while($row = mysql_fetch_array($query)) { 
    $cat_id = $cat_id; // where row 0 is cat id 
    echo "<a href='forum.php?id='".$cat_id."'>".$cat_title."</a><br>"; // where row 1 is cat name 
    $ret = mysql_query("SELECT * 
                        FROM forums 
                        WHERE cat_id = '$cat_id' 
                        ORDER BY order_id ASC"); // cat is a field which is linked with cat id 
    $r = mysql_num_rows($ret); 
    for($j = 0; $j < $r; ++$j) { 
    $row = mysql_fetch_row($ret); 
    echo "<a href='forum.php?sub_id='".$row[0]."'>".$row[1]."</a><br>"; 
    } 
    } 
    
    ?>
    and it's saying
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site200/fst/var/www/html/phases78/forums/forums2.php on line 141
    on this line
    Code:
    while($row = mysql_fetch_array($query)) {

  13. #13
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $cat_id = $row[0] not $cat_id!!!
    try with $row = mysql_fetch_row($query);
    wrong
    <a href='forum.php?id='".$cat_id."'>".$cat_title."</a>

    right
    <a href='forum.php?id='".$cat_id."'>".$row[1]."</a>

  14. #14
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, "Parse error: parse error, unexpected T_ECHO in /home/virtual/site200/fst/var/www/html/phases78/forums/forums2.php on line 143"

    on
    Code:
    echo "<a href='forum.php?id='".$cat_id."'>".$row[1]."</a><br>"; // where row 1 is cat name
    (sorry bout writing over the row's.. I got confused with the side notes)

  15. #15
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it out of the question to use the original forums.php I posted on my initial message?

    It lists all the categories, and the categories link to "profile2.php?cat_id=<? echo $cat_id ?>"

    So... is it not possible to have profile2 list the categories just like this page, but then when it gets to whichever category is passed through the link, spit out it's subcategories too?

    Using that $i maybe?

  16. #16
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wrong
    echo "<a href='forum.php?id='".$cat_id."'>".$row[1]."</a><br>";
    right
    echo "<a href='forum.php?id=".$cat_id."'>".$row[1]."</a><br>";
    ive put a single quote after id=' sorry my mistake

  17. #17
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Same error still. Maybe cuz of all the "s? Here is the whole thing just in case:

    Code:
    <?php
    
    require 'db_connect.php';
    
    $query = mysql_query("SELECT * 
                          FROM categories 
                          ORDER BY order_id ASC"); 
    while($row = mysql_fetch_array($query)) { 
    $cat_id = $row[0] // where row 0 is cat id 
    echo "<a href='forum.php?id=".$cat_id."'>".$row[1]."</a><br>"; // where row 1 is cat name 
    $ret = mysql_query("SELECT * 
                        FROM forums 
                        WHERE cat_id = '$cat_id' 
                        ORDER BY order_id ASC"); // cat is a field which is linked with cat id 
    $r = mysql_num_rows($ret); 
    for($j = 0; $j < $r; ++$j) { 
    $row = mysql_fetch_row($ret); 
    echo "<a href='forum.php?sub_id='".$row[0]."'>".$row[1]."</a><br>"; 
    } 
    } 
    
    ?>

  18. #18
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look at the second echo...
    delete the single quote ' after id=

  19. #19
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shoot, my mistake..

    However still getting the same error, on the first echo line.

    I bet you hate me by now huh? Don't think your help is going unappreciated here, you're the only person to stay with me this long on this! I do highly appreciate it.

  20. #20
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok got past THAT problem. Needed a semicolon at the end of the line before that echo.

    Now at least the page kinda loads before I get the errors, instead of the white screen. That's progress right? :P

    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site200/fst/var/www/html/phases78/forums/forums2.php on line 141
    on:
    Code:
    while($row = mysql_fetch_array($query)) {
    p.s., I already tried the substitute you mentioned earlier,
    Code:
    $row = mysql_fetch_row($query);
    (unless I was supposed to remove the "while(" too...)

  21. #21
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just change fetch_array with fetch_row

  22. #22
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource

  23. #23
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so try $row = mysql_num_rows($query)

  24. #24
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    tn
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still gettin' a no.

    Starting to lose faith.. maybe I should just try again later and give me and you both a break.

  25. #25
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its impossible that neither of those three resolution wont work!
    can i see all the page u use!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •