ผมมี table ีuser ที่มี field ดังนี้
user_id name upline salary
1 sorn 1000
2 dream 1 1000
3 man 2 1000
4 net 2 2000
5 nit 3 3000
6 don 3 3000
ผมเขียนโค๊ดให้มันออกมาเป็นแบบนี้ได้แล้ว Code (PHP)
include("connectdb.php");
mysql_select_db("gano",$con) or die ("ไม่พบฐานข้อมูล");
$str_sql="SELECT * FROM user WHERE gano_id='" . $user_id . "'";
$result=mysql_query($str_sql,$con) or die("โค๊ด $str_sql ผิด");
while($row=mysql_fetch_array($result)){
echo $row["name"] . "<br/>";
$str_loop1="SELECT * FROM user WHERE upline='" . $row['user_id'] . "'";
}
$result_loop1=mysql_query($str_loop1,$con) or die("โค๊ด $str_loop1 ผิด");
while($row_loop1=mysql_fetch_array($result_loop1)){
echo $row_loop1["name"] . "<br/>";
$str_sql_loop2="SELECT * FROM user WHERE upline='" . $row_loop1['user_id'] . "'";
$result_loop2=mysql_query($str_sql_loop2,$con) or die("โค๊ด $str_sql_loop2 ผิด");
while($row_loop2=mysql_fetch_array($result_loop2)){
echo $row_loop2["name"] . "<br/>";
}
}