PHP / Smarty的从数据库嵌套数组 [英] PHP/Smarty Nested array from DB

查看:126
本文介绍了PHP / Smarty的从数据库嵌套数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

玉家伙我试图通过嵌套查询访问PHP / MySQL数据库。

Ok guys I am trying to access a php/mysql db via a nested query.

如。我有2表1)个人和2)注册。我有一个注册ID refferal标签。所以,当他在用户登录应能看到4个级别的注册低于他的身份证做了。

eg. I have 2 tables 1) persons and 2) registration. I have a refferal id tab in registrations. So when a user logs in he should be able to see 4 levels of registrations done below his id.

表结构

报名
ID |注册ID | regtype |上线ID | UID |名字|中间名|姓氏最后等

Registration id | Registration ID | regtype | Upline ID | uid |FirstName |MiddleName | LastName Last etc

个人

ID | UID |上线| FNAME | miname | LNAME |等和许多其他细节

id| uid | upline | fname | miname | lname | etc and lot of other details

我现在做它像这样去的第一级。

Now i am doing it like this to get to the first level.

$tid=$_GET['tid'];
$con = mysql_connect("localhost","db","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
else
{  
mysql_select_db("db", $con);
$resulta = mysql_query("SELECT * FROM personal WHERE id=$tid ");
$counta = mysql_num_rows($resulta);
while ($rowa = mysql_fetch_assoc($resulta)) {
$selid=$rowa['uid'];
$amount=$rowa['amountf'];
$plan=$rowa['planname'];
$resultfulla[] = $rowa;
}
$resultb = mysql_query("SELECT * FROM regtab WHERE regtab.upline=$selid " );
$countb = mysql_num_rows($resultb);
$rowz=array();
while ($rowb = mysql_fetch_assoc($resultb)) {
$rowz[] = $rowb;
}

现在我能够去一个级别但我怎么周期的第二个数组,并且将在以后生产得到一个树形结构的阵列。左右....任何帮助......

Now i am able to get to one level but how do i cycle the second array and the arrays that will be produced later to get a tree structure. Or so....any help....

使用数组rowz我能够存储我也做了一号线REGSTRATION的结果。现在,使用这个数组,我需要找出如何让已低于阵列rowz完成第二行登记.....

With the array rowz i am able to store the results of the 1st line regstration that i have done. Now using this array i need to find out how to get the second line registrations that have been done below array rowz.....

推荐答案

加入您的疑问并得到结果。

Join your queries and get the result.

$sql = "SELECT * FROM personal 
        LEFT JOIN regtab ON regtab.upline = personal.uid
        WHERE personal .id=".$tid;

获取在PHP中所有的结果。

Get all the results in php.

这篇关于PHP / Smarty的从数据库嵌套数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆