I now understand what I need to do, after doing some reading on indexes.
I have adjusted my mysql database as follows. I have one category table...
id category
1 example 1
2 example 2
3 example 3
4 example 4
I have one subcategory table...
cat_id subcategory
1 sub 1
1 sub 2
3 sub 3
4 sub 4
4 sub 5
4 sub 6
So....
Subs 1 + 2 are sub categories of example 1.
Sub 3 is a sub category of example 3.
Subs 4, 5 + 6 are sub categories of example 4 and so on.
cat_id and id relate to each other. I have called this in the database and displayed the results...
<html>
<body>
<table border="1" align="center">
<tr>
<td>ID</td>
<td>Category</td>
<td>Subcategorys</td>
<td>Edit</td>
</tr>
<?php
include 'mysql.php';
$category = mysql_query("select * from category, subcategory where category.id = subcategory.cat_id ORDER BY id") or die (mysql());
while ($row = mysql_fetch_array($category))
{
$id = $row['id'];
$edit = "editcats.php?id=$id";
?>
<tr>
<td>
<?php echo $id; ?>
</td>
<td>
<?php echo $row['category']; ?>
</td>
<td>
<?php echo $row['subcategory']; ?>
</td>
<td>
<center>
<form action="<?php echo $edit; ?>" method="POST">
<input type="image" src="edit.gif">
</center>
</form>
</td>
</tr>
<?php
}
mysql_free_result($database);
include 'closemysql.php';
?>
</table>
</body>
</html>
This works like a charm 🙂 But using this code, it lists everything. Using the example above and my code this will result in something like this...
------------------------------------
category subcategory
------------------------------------
example 1 sub 1
------------------------------------
example 1 sub 2
------------------------------------
example 3 sub 3
------------------------------------
example 4 sub 4
------------------------------------
example 4 sub 5
------------------------------------
example 4 sub 6
------------------------------------
etc
How do I make it so it will just show one heading from category and list the subcategories? like this...
----------------------------------
category subcategory
--------------------------------
example 1 sub 1
sub 2
----------------------------------
example 2 No subcategories
----------------------------------
example 3 sub 3
----------------------------------
example 4 sub 4
sub 5
sub 6
---------------------------------
Hope it makes sense! :p