Jump to content

Site Navigation Categories via MySQL... Please Help!


BlackKite

Recommended Posts

Ok, so basically designing myself a management system for my one site so that its easier for me and the people that help me to upload pages. I've been doing good with it until now. What i'm trying to do is get my navigation links so print themselves in their correct categories. I've been able to call them from SQL and be turned into links, but I can't seem to figure out how to sort them into the categories.

 

In MySQL I have three pages; one, two, and main. One and Two have an ID_CAT of 2 and Main has and ID_CAT of 1.  My goal is to list them in order of ID_CAT 1 then 2 on my navigation, but without having to actually state 1 and 2. For example, and if statement of "if ID_CAT = 1 echo". <- thats what I don't want to have to do because I'm trying to make this so that I don't have to go into my actual files ever again, and everything can be done via a nice neat control panel.

 

Here's my navigation code so far.

$query = "SELECT * FROM pages"; 

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
        echo "<a href=\"http://www.neohound.com/sms/ver1/index.php?id=1&url=";
echo $row['url'];
        echo "\">";
        echo $row['name'];
        echo "</a>";
echo "<br />";
}

 

If anyone can be kind enough to at least point me in the right direction, i would greatly appreciate it. Thanks so much!  :'( I'm a complete n00b at this SQL stuff, haha.

Link to comment
Share on other sites

I think you're wanting to change the order in which you pull the data from the tables - "pages" in this case.

 

You can accomplish this by adding an "ORDER BY" clause on the end, somethign like this:

 

SELECT * FROM `pages` ORDER BY `two` ASC

 

ASC means sort in ascending order. You can also use DESC to reverse sort.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.