Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 11-29-2008, 03:58 PM Navigation Help
Average Talker

Posts: 16
Trades: 0
Hey everyone, I am attempting to create a simple PHP and MySQL navigation system. Here is my navigation table:

====================
id category title link
====================

I want the navigation to have parent like "Main" and have links that fit that category under it. Basically I have 5 or 6 links under 4 different categories. Here is my current code:

PHP Code:
<?php
$sql 
"SELECT id, category, title, link FROM navigation ORDER BY category desc"
$result $db->sql_query($sql); 
$row $db->sql_fetchrow($result);

            print   
"<ul class='nav'>
                <li><a href='#' class='home'>" 
$row['category'] . "</a></li>
<div class='boxin'>
                     <a class='active' href='" 
$row['link'] . "'>" $row['title'] . "</a><br />
                     </div>"
                     
?>
This displays only one category and that one link under the category at a time. So how do I make it show all of the categories and links under the correct parent. I hope I am not being to confusing. Thanks! .
Ghost Sniper X is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-30-2008, 04:42 PM Re: Navigation Help
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try something like this:

PHP Code:
<?php
$sql 
"SELECT id, category, title, link FROM navigation ORDER BY category DESC";
if (
$result $db->sql_query($sql)) {
  
$current_category '';
  while (
$row $db->sql_fetchrow($result)) {
    if (
$current_category != $row['category']) {
      if (
$current_category != '') {
        echo 
'</ul>';
      }
      echo 
'<ul class="nav">';
      
$current_category $row['category'];
    }
    echo 
'  <li>
    <a href="#" class="home">' 
$row['category'] , '</a>
    <div class="boxin">
      <a class="active" href="' 
$row["link"] . '">' $row["title"] . '</a>
    </div>
  </li>'
;
  }
}
?>
I'm not totally sure about your $db object, though, as that's not an instance of any MySQL interface with which I'm familiar, but the structure should be what you need.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-02-2008, 12:11 AM Re: Navigation Help
Average Talker

Posts: 16
Trades: 0
Hey thanks man, it shows all of the results. Only problem is, the categories don't separate correctly. Like in the Table I have:

====================
id category title link
====================
1 test1 test lol
2 test1 lol1 rofl

So the output is this:
test1
-test
test1
-lol1

When it should be:
test1
-test
-lol1

So I am trying to fix that but I am having a hard time. Thanks for the help, I really appreciate it! .
Ghost Sniper X is offline
Reply With Quote
View Public Profile
 
Old 12-02-2008, 11:42 AM Re: Navigation Help
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Oh. This will help, then:

PHP Code:
<?php
$sql 
"SELECT id, category, title, link FROM navigation ORDER BY category DESC";
if (
$result $db->sql_query($sql)) {
  
$current_category '';
  echo 
'<ul>';
  while (
$row $db->sql_fetchrow($result)) {
    if (
$current_category != $row['category']) {
      if (
$current_category != '') {
        echo 
'  </ul>
</li>'
;
      }
      echo 
'
  <li class="nav">
    <a href="#" class="home">' 
$row['category'] , '</a>
    <ul>
'
;
      
$current_category $row['category'];
    }
    echo 
'      <li>
        <div class="boxin"><a class="active" href="' 
$row["link"] , '">' $row["title"] , '</a></div>
      </li>
'
;
  }
  if (
$current_category != '') {
        echo 
'    </ul>
  </li>
'
;
  }
  echo 
'</ul>';
}
?>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Navigation Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13379 seconds with 12 queries