Help - Search - Members - Calendar
Full Version: Link Directory
Weborum Webmaster Forum > Web Page Design > PHP
aftabn10
I am trying to create a web directory for a uni project. I have got two tables one is a list of all my categories and the second table has all the subcategories but i am struggling on how to display this with my queries. The following are my tables;

cat_id | category cat_id | sub_cat
1 | Bakeries 1 | Highfields Halal Bakery
2 | Business Stationery 1 | Delicious Corner
3 | Cafes
4 | Catering
5 | Finance
6 | Health
7 | Home
8 | Indian Sweets
9 | Motors
10 | Restaurants
11 | Shopping
12 | Takeaway
13 | Weddings
14 | Extra
15| Extra 2

At the moment I am running the query

$query = "SELECT *
FROM category
";

$result = mysql_query($query) or die('Error, query failed');

// print the student info in table
echo '<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>';

$i = 1;

while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

// Display each record.
echo "<td><table border=\"1\" height=\"42\" width=\"212\" class=\"style1\">
<td class=\"col\"><width=\"103\" align=\"left\"><div style=\"padding-left:34px; padding-bottom:8px\">{$row['category']}</class>
</div></td>
</table></td>\n";
if (($i++ % 3) == false) {
echo "</tr>\n";
}
}
echo '</table>';
mysql_close(); // Close the database connection.
?>

where my data is displayed in a table e.g. (3 columns and 5 rows)

Bakeries Business Stationery Cafes (Shisha)

where i am struggling is that i would like to have the subcategories from table 2 to appear along each matching column. e.g.

Bakeries
Highfields Halal Bakery, Delicious Corner, etc..

If any1 can please help or guide me in the right direction.
Joe
What you have just shown us isn't your tables but your table fields. If you have two tables which are integral to eachother you must have a primary key in one table linking to a foreign key in the other, without these, there is nothing to join.

If you post your actual SQL table code I may be able to help you.

Although, now I see you decided to cross-post your question to another forum;

http://www.htmlforums.com/showthread.php?t=76414
xanderman
<?php
$query = "SELECT * FROM `category` ORDER BY `cat_id` DESC";
$result = mysql_query($query) or die('Error, query failed');
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr>\n\r";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "$category <br>\n\r";
}
echo "</tr>\n\r";
echo "</table>\n\r";
mysql_close();
?>

Try that
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.