關於php、mysql,二叉樹高手來幫忙,如何計算下面某個節點是否在某節點下面?

來源:互聯網
上載者:User
本帖最後由 kwdpx 於 2013-09-05 16:57:47 編輯




資料庫member結構:
編號 上級ID 金額
id sh1 jine
1001 999 49
1002 1001 20
1003 1001 29
1004 1002 10
1005 1003 12
1006 1002 10
1007 1006 4
1008 1003 17
1013 1008 8
1015 1006 6
1021 1008 9
……

比如想知道ID:1021在不在1003下面?如果在就顯示在,如果不在1003下面就顯示不在:

if(){
echo "在";
}else{
echo "不在";
exit();
}


回複討論(解決方案)

組織成二叉樹的資料結構,很明顯通過遞迴查詢就可以查到.

組織成二叉樹的資料結構,很明顯通過遞迴查詢就可以查到.

是的,但不會,麻煩幫寫出代碼,謝謝!

我來撿分了function show($a,$b){  $res = mysql_query("select sh1 from member where id=$a");  $row = mysql_fetch_row($res);  if($row[0] == $b)  return '在';  elseif($row[0] == NULL)   return '不在';  else{   echo show($row[0],$b);    }} echo show(1004,1001);echo '
';echo show(1004,10031);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.