Jump to content

display database info help


soddengecko

Recommended Posts

hi all

I have a database (links) with two tables (catagories) and (info)

I have set up a form that allows the creation of a category, which is put into the catagory table and outputted into a drop down list.

then you select an option from the list, type in your url and title and submit the data. this data is then added to the info table under (id) (category) (url) and (title)

this form is working well.

The issue i have is displaying the data. i want each category to be displayed seperatly like it does with a link manager. so everythign that has a catagory MISC is displayed in one list.

I can do this when i know what the catagories are going to be, but this will be a production app for myself and some colleagues to store links to different stuff.

how do i call the links fromt he database and have each category split into a different list and obviously have the name of the category displayed once as the title to the list?

does anyone have any info? i'm pulling my hair out puzzling over this

thank in advance
Link to comment
Share on other sites

(2) options

Option (1), fetch the categories, then when looping that result, fetch the topics in category loop (1 query for the categories, 1 query per category topic set)
Option (2), Join the tables and order by the category, out side your loop assign a category test variable to '', then inside your query loop have a if() block that tests the current category against the test variable, if it doesn't match, print the new header and store that value into the test variable. (1 query)

[code]
test_category = ''

while (db_loop)
{
if ( test_category != db_result_category )
{
// print header, db_result_category

// test_category = db_result_category
}

// print category topic, topic data
}
[code]


me![/code][/code]
Link to comment
Share on other sites

hi

thanks for the reply. I am not really following what you mean, im pretty new to all this. this is the script i am using to display the links and categories

<?php

$sql = "SELECT * FROM info ORDER BY catagory";
$result = mysql_query($sql) or die('There are currently no links in the database.');
while ($row = mysql_fetch_assoc($result))
{
  $catagory = $row['catagory'];
  $url = $row['url'];
  $title = $row['title'];
  if ($catagory != $temp)

  echo "</ul>\n</div>\n\n<div class='left'>\n<h1>$catagory</h1>\n<ul>\n";
  $temp = $catagory;
  echo "<li><a href='$url' target='_blank'>$title</a></li>\n";

}
echo "</ul>\n";
echo "</div>\n\n";
?>

as long as my sql SELECT statment is ordered by category everythig is printed to the page correctly, but not in alphabetical order which is what i need.

could you explain your code a little further please?

kind regards
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.