|
 |
|
สอบถามเรื่่อง การแสดงผลของระบบ MLM (Multi Level Marketing) |
|
 |
|
|
 |
 |
|
ลงโค้ดพร้อมฐานข้อมูล เลยครับ.
|
 |
 |
 |
 |
Date :
2014-08-28 19:59:31 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้ลง Code เลยครับ แต่ฐานข้อมูล มีละครับ
|
 |
 |
 |
 |
Date :
2014-09-01 10:28:29 |
By :
kimzuhum |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมทำได้ถึงแค่นี้เองครับ
ใช้ while วนลูปซ้อนๆ กันแต่ตารางมันออกมามั่วหมดเลยครับ
Code (PHP)
<?php
$hostname = "localhost";
$hostusername = "root";
$hostpassword = "root";
$link = mysql_connect($hostname,$hostusername,$hostpassword,"TRUE");
mysql_select_db('mlm',$link);
/*
$sqlb="SELECT * FROM tb_parent WHERE parent_id='". $rows['use_id'] ."'";//4
$qryb= mysql_query($sqlb);
$Bnumrow = mysql_num_rows($qryb);
$Bnumrow;
while($rowb=mysql_fetch_array($qryb)){;
echo " Procition : ".$rowb['form_type']." ".$rowb['use_id']."<br/>"; //4
}// end while1
}// end while2*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if($_REQUEST['platinum_id']){
$platinum_id = $_REQUEST['platinum_id'];
}else{
$platinum_id = '0000001';
}
$sqlp="SELECT * FROM tb_parent WHERE user_id = '$platinum_id' "; //1
$qryp= mysql_query($sqlp);
$rowp=mysql_fetch_array($qryp);
$Pnumrow = mysql_num_rows($qryp);
$Pnumrow;
?>
<table width="100%" border="1" align="center" cellpadding="5">
<tr>
<td colspan="27" align="center">แผนธุรกิจตัวแทนขายอิสระ</td>
</tr>
<tr>
<td colspan="27" align="center" bgcolor="#00FF00">
<?php echo 'Procition : '.$rowp['form_type'].' '.$rowp['user_id']."<br/>";?></td>
</tr>
<?php
$i=0;
$sqlg="SELECT * FROM tb_parent WHERE parent_id='". $rowp['user_id'] ."' ORDER BY user_id";//2
$qryg= mysql_query($sqlg);
$Gnumrow = mysql_num_rows($qryg);
$Gnumrow;
while($rowg=mysql_fetch_array($qryg)){;
if($i==0){
?>
<tr>
<?php }
if($i<=3){$i++;// วนลูปจนครบ 3?>
<td colspan="9" align="center" bgcolor="#FFFF66"><?php echo ' Procition : '.$i.$rowg['form_type'].' '.$rowg['user_id']."<br/>";?>
<?php
$sqls="SELECT * FROM tb_parent WHERE parent_id='". $rowg['user_id'] ."'";//3
$qrys= mysql_query($sqls);
while($rows=mysql_fetch_array($qrys)){
echo ' Procition : '.$rows['form_type']." ".$rows['user_id']."";
/*$sqlb="SELECT * FROM tb_parent WHERE parent_id='". $rows['user_id'] ."'";//4
$qryb= mysql_query($sqlb);
echo "<br/>";
while($rowb=mysql_fetch_array($qryb)){
echo ' Procition : '.$rowb['form_type']." ".$rowb['user_id']."";
}*/
}
?>
</td>
<?php }?>
<?php }// end while1 ?>
<?php if($i!=3 and $i!=0){?>
<td colspan="9" align="center" bgcolor="#FFFF66">Non member <br/></td>
<?php }?>
<?php if($i==3){?></tr><?php }?>
<!--<tr>
<td colspan="3" align="center" bgcolor="#FFFFCC">S1<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S2<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S3<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S4<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S5<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S6<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S7<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S8<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td colspan="3" align="center" bgcolor="#FFFFCC">S9<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">B1<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B2<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B3<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B4<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B5<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B6<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B7<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B8<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B9<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B10<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B11<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B12<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B13<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B14<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B15<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B16<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B17<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B18<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B19<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B20<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B21<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B22<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B23<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B24<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B25<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B26<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
<td bgcolor="#CCCCCC">B27<br />
<img src='icon.gif' width='33' height='45' alt='No Record' longdesc='#' /></td>
</tr>-->
<?php //}// end while3?>
</table>
</body>
</html>
|
ประวัติการแก้ไข 2014-09-01 10:56:27
 |
 |
 |
 |
Date :
2014-09-01 10:54:27 |
By :
kimzuhum |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตารางลักษณะนี้ก็พอทำได้อยู่หรอก แต่ดูยาก
ยิ่งข้อมูลเยอะๆ แล้วน่าจะดูไม่รู้เรื่องเลยแหละ
แนะนำว่าน่าจะ display แบบ treeview จะดีกว่า
ใช้โค้ดแบบ recursive ทำเอา
|
 |
 |
 |
 |
Date :
2014-09-01 13:48:55 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอจะมีแนวไหมครับ ผม มึนมากเลยครับ ช่วยหน่อยน่ะครับ ^^
|
 |
 |
 |
 |
Date :
2014-09-04 14:43:10 |
By :
kimzuhum |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
recursive function ครับ
จากตัวอย่าง field ที่ให้ในฐานข้อมูล ถ้า parent_id เป็น 0000000 คงแปลว่า เป็น head สูงสุดแล้ว
ถ้าจะหา down line ลงไปเรื่อยๆ
ลองทำความเข้าใจ แล้วเอาไปประยุกต์เพิ่มเติมดูนะครับ ให้ code ไม่ละเอียด
Code (PHP)
function get_down_line($parent_id)
{
// 1. นำ Parent ID ไป SELECT หาว่าใครมี Parent ID นี้บ้าง
// 2. SELECT user_id, parent_id FROM table WHERE parent_id=$parent_id
// 3. สมมติว่าหาได้แล้วว่า ใครที่มี Parent ID อันนี้ แล้วเก็บใส่แอเรย์ $member
// 4. นำ $member มา loop ตามจำนวน member ที่ได้
foreach($member as $user)
{
get_down_line($user['user_id']);
}
}
//เรียกใช้ครั้งแรก
get_down_line("0000000");
ลองไปไล่การทำงาน code ดู แล้วประยุกต์ใช้กับเรื่อง การแสดงผลดูนะครับ
อย่างที่ความเห็นบนๆ บอกว่า ลองดูพวก แสดงผลเป็น treeview จะง่ายกว่า ลองหาพวก jQuery + HTML ที่แสดงผลพวก treeview เพิ่มเติม
|
 |
 |
 |
 |
Date :
2014-09-04 22:02:53 |
By :
Likito |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พึ่งเข้าไปดูลิงค์ ที่แนบมา
อันนั้นเขาทำเป็น HTML + Javascript + CSS
ก็ได้ไอเดียเพิ่มเติม
วิธีที่ผมให้ไปอันแรกถ้าในแง่การใช้งานจริงแล้วไม่ดีสักเท่าไร เพราะจะมีการ Query Database หลายครั้งมาก
เอา parent_id ไป query หา child_id แล้วเอา child_id ไป query หา child_id ต่อไปอีกเรื่อยๆ จนกว่าจะไม่มี
ถ้าสมาชิกเยอะๆ อาจจะต้อง query เป็น สิบ เป็นร้อย เป็นพัน ครั้ง
ถ้าลองเปลี่ยน query แค่ครั้งเดียวทั้งตาราง member นั้น
แล้วลองเลียนแบบ algorithm ของ Javascript ในลิงค์นั้น ให้เป็นรูปแบบ PHP ก็ได้แล้วนะ
หรืออีกวิธีนึงก็ใช้ php ทำ query ทั้งตาราง member เป็นตัวแปร แล้ว ส่งเป็น JSON หรือ XML ในรูปแบบอื่นๆที่ถนัด ใช้ Javascript รับค่าที่ได้มานั้น แปลงให้อยู่ในรูปแบบ array เดียวกันกับตัวอย่างที่เขามีมาให้ ก็ใช้งานได้แล้ว เอา array นั้นไปใช้แทน
|
 |
 |
 |
 |
Date :
2014-09-04 22:17:02 |
By :
Likito |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆเลยครับ สำหรับแนวทาง จะลองเอาไปปรับใช้ดูครับ ได้เรื่องยังไงจัะเอามาแบ่งปันครับ เพราะไปหาดูแล้ว ไม่ค่อยมีใครให้ตัวอย่สงหรือแนวทางเลยมีแต่ ขายๆๆ
|
 |
 |
 |
 |
Date :
2014-09-04 22:48:26 |
By :
kimzuhum |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|