PDA

View Full Version : Populated headers and results


danielwarner
11-17-2005, 04:23 PM
can anyone help me with this please....

what i need help with is i want to create a links menu for a website. i will display these links from a database. My problem is that i need to have headers for the links... ex:

Link Header .... Example
-link
-link
-link
-link

Link Header .... Example
-link
-link
-link
-link

there is also a function that creates the headers... how would i go about doing this? would i put a query inside a query?

Tynan
11-17-2005, 05:13 PM
MYSQl is only going to provide you with variables

it's going to be php that takes those variables and helps to generate the html for the menus

the db will need to hold the different header/link groups on different lines is all the MYSQL detail

I'd write the html first then rewrite the php bits to echo in the variables

a little loop to write the presumably variable numbers of links for each group, and the variable amount of groups if applicable

(newbie myself)

danielwarner
11-17-2005, 06:02 PM
damn. Sounds hard.

can anyone help me here please. i wont have a set number of links per header so it would probably need some sort of count function.

Kid Charming
11-17-2005, 10:50 PM
Here's how I do this sort of thing. I'm assuming a db structure with fields 'link' and 'category'. I'm also assuming you're doing this in PHP, but the logic's the same for whatever language.


$query = "SELECT link,category FROM table";
$result = mysql_query($query) or die(mysql_error());

//initialize category checker variable
$prev_cat = '';

while( $row = mysql_fetch_assoc($result) )
{
//check current $row's category against $prev_cat
//if it's different, we'll need to echo a new header
if( $row['category'] != $prev_cat )
{
echo $row['category'];
}

echo $row['link'];

//set $prev_cat to current $row's cat for next iteration
$prev_cat = $row['category'];
}

GJay
11-17-2005, 11:54 PM
you'd presumably want to order by category in that query...

Kid Charming
11-18-2005, 12:21 AM
you'd presumably want to order by category in that query...

Erm...yep. :p