Jump to content

Getting from sql database to something I can use


SyncViews

Recommended Posts

database structure

categorys:
category_id
category_name
category_display

sections:
section_id
category_id
section_name
section_decription
section_display

The category_id in the sections tabel says what category the section is under. I need to query the database and get these into some arrays but I'm not sure what is the best way. Each "group" needs to be order by the _display valuse in assending order

 

category
  |
  |--section -> section data
  |
  |--section -> section data

category
  |
  |--section -> section data

So I should have 3 "layers" of arrays eg

Eg to get the name of the first section in the first catagory:

$data[0][0]["section_name"]

 

I have got it to an extent but it doubles up the category data and I'm not sure it's a particualy fast query either... The other problem is I can't see a good way to seperate the catagorys so I can insert the catagory names in between where as with a big array I could just use a double foreach loop

 

<?php
$query = mysql_query('
	SELECT
	category.category_name,
	sections.sections_name, sections.sections_desc
	FROM categorys, sections
	WHERE category.category_id=category.category_id
	ORDER BY categorys.display, sections.display
	') or exit(mysql_error());
?>

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.