首先,改变你的数据库设计......
table factories
-----------------
idFactories
idCategories (int) <---- add this field
Factoryname
Postcode
...
然后,查询属于特定类别的工厂。通过idCategories
链接传递:
创建链接:
// sql to get all categories from the DB
$sql="SELECT * FROM categories ORDER BY Categorie"
// --- insert your code to pull the data from your DB here ---
// building your links on the left column
// assuming all rows from the sql above are in array $categories
foreach ($categories as $cat)
echo '<a href="thispage.php?id='.$cat['idCategories'].'">'.$cat['Categories'].'</a>';
根据点击的类别显示工厂......在文件的开头:
if (isset($_GET['id']) && intval($_GET['id'])>0)
$id=intval($_GET['id']);
else $id=0;
if ($id>0) {
$sql="SELECT * FROM factories WHERE idCategories=$id";
// --- insert your code to pull the data from your DB here ---
// store all the rows in array $factories
}
输出工厂:
if ($id>0) {
foreach ($factories as $fac) {
// code for echoing the data
}
} else {
echo "select a category on the left to show the factories...";
}
糟糕,我看到您在问题中更改了类别和工厂之间的关系。基本上,技术是相同的,只是 sql 会改变。