Jump to content

[SOLVED] Oh craps! Need help echoing mysql data into xhtml list


lilwing

Recommended Posts

I sure hope someone can help with this problem, I have been up all night trying to figure it out.

 

Basically, I have a table called hyperlinks, with the columns: HREF, Name, Category, PrimaryCategory, and LinkOrder.

 

I am trying to use a database for holding the links in the navigation bar. HREF is the source of the URL, Name goes between the a tags, category is either primary or secondary (primary would be the main navigation, and secondary would be the subnavigation... kind of like a dropdown) PrimaryCategory is the name of the primary category which a given set of secondary links falls under... it is null for all entries with 'primary' in the Category field. Link order is an integer entry, used to order the links.

 

With some frustration, and help from the boards, I have finally gotten the primary navigation links to show. What I haven't been able to do, is get the secondary links to appear under the proper primary navigation link.

 

For example, say I want the list to function something like this:

 

<ul>

<li><a href="#">home</a>

 

<li><a href="#">what should be under home</a>

 

</li>

</ul>

 

So I want it to be something like this:

 

Where PrimaryCategory = PrimaryName;

<ul>

<li><a href="PrimaryHREF"">PrimaryName</a>

 

<a href="SecondaryHREF">SecondaryName</a>

 

</li>

</ul>

 

I've wasted quite a bit of time trying to figure this out. However it is very important. I hope you can help. Here is the source:

 

<?php
$query = mysql_query('SELECT * FROM hyperlinks ORDER BY LinkOrder ASC') 
or die(mysql_error());

while($row = mysql_fetch_array($query)) {

while($row[Category] = 'primary') {

$primaryName = $row[Name];
$primaryHREF = $row [hrEF];

$primaryCategory = $row['PrimaryCategory'];
$secondaryName = $row['Name'];
$secondaryHREF = $row['HREF'];

		echo ('<li class="off"><a href="http://www.sfisk12.org/index.php?pageid='.$primaryHREF.'">'.$primaryName.'</a>');

			echo ('<ul>');
			echo ('<li><a href="'.$secondaryHREF.'"></a>'.$secondaryName.'</li>');
			echo('</ul>');

		echo ('</li>');
?>

this is what i have so far. not sure where i am making a mistake. any help?

 


<?php

$query = mysql_query('SELECT * FROM hyperlinks WHERE Category="primary" ORDER BY LinkOrder ASC') 
or die(mysql_error());

$row = mysql_fetch_array($query);


$primaryName = $row['Name'];
$primaryHREF = $row ['HREF'];

		echo ('<li class="off"><a href="'.$primaryHREF.'">'.$primaryName.'</a>');

		$query2 = mysql_query('SELECT * FROM hyperlinks WHERE Category="secondary" AND PrimaryCategory="$primaryName" ORDER BY LinkOrder ASC') 
or die(mysql_error());

$row = mysql_fetch_array($query2);


			$secondaryName = $row2['Name'];
			$secondaryHREF = $row2['HREF'];

			$primaryCategory = $row2['PrimaryCategory'];


			echo ('<ul>');
			echo ('<li><a href="'.$secondaryHREF.'"></a>'.$secondaryName.'</li>');
			echo('</ul>');

		echo ('</li>');
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.