2013-07-09 43 views
1

我有一个具有100,000个位置的mysql表,我想应用嵌套集模型以便我可以轻松地生成有序列表。出于显而易见的原因,这是手动完成的一项大任务,所以我希望考虑到我的数据结构非常好,它可以用SQL(或PHP作为后备)编写。下面是表:MySQL在大型数据列表上自动生成嵌套集模型?

Id    place    county   country 
1    Abberly   Worcestershire England 
2    Abberton   Worcestershire England 
3    Abbey Field  Essex   England 
4    Abbey St Bathans Scottish Border Scotland 
5    Abbeycwmhir  Powys   Wales 

我的计划是将内容传送到一个表像下面这样:

id  location   _left _right 
1  England  
2  Wales 
3  Scotland 
4  Essex 
5  Powys 
6  Scottish Border 
7  Worcestershire 
8  Abberyly 
9  Abberton 
10  Abbey Field 
11  Abbey St Bathans 
12  Abbeycwmhir 

任何帮助,不胜感激!

+0

多数民众赞成在可能的情况下,你是否尝试过自己? – Tredged

+0

我很难找到它。我不确定是否最好的路线是建立一个只有id,name,_left,_right的新表,因为一旦这个表被移动到一个嵌套模型中,它将使得更容易选择'Worcestershire'作为'名称“,然后找到它的所有孩子的L/R值? – James

回答

1

MySQL表中包含100,000行?然后在它之前做一些类似于表格的事情,它会以tabel的形式显示出所有你想要的东西。

<?php 
$query = "SELECT id, name, country FROM table"; 
if ($result = mysqli_query($connect, $query)) { 
while ($get = mysqli_fetch_assoc($result)) { 
echo"<tr><td>" . $get['id'] . "</td>"; 
echo"<td>" . $get['name'] . "</td></tr>"; 
echo"<td>" . $get['country'] . "</td></tr>";          
} 
} 
?> 

一样,如果它helpd。

+0

我应该提到它需要嵌套,以便我可以查询另一个表,如下所示:SELECT * FROM data WHERE locationId IN(2,3) – James