Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by sasa

  1. you can binary tree put in array in this way

    1. root node put on index 1 in array

    2. lchild of node with index n put in array element with indeks 2*n

    3. rchild of node with index n put in array element with indeks 2*n+1

     

    parent element of element with index n is in position (int)(n/2)

     

    level of element with index n is log(n, 2) (root element is level 0)

     

    on n-th level is elements with index from pow(2, n) to pow(2, n+1)-1

     

    here is code for put tree in array

     <?php
    function tree_gather($node)   //Function to calculate count
      {
        $tree = array(1 => $node);
        b_tree($node, 1, &$tree);
        return $tree;
      } 
      function b_tree($node, $index, &$tree){
          $sql = "SELECT lchild,rchild FROM tree WHERE parent = '$node'";
          $execsql = mysql_query($sql);
          if($array = mysql_fetch_array($execsql)){
              if(!empty($array['lchild'])){
                  $tree[$index * 2] = $array['lchild'];
                  b_tree($array['lchild'], $index * 2, &$tree);
              }
              if(!empty($array['rchild'])){
                  $tree[$index * 2 + 1] = $array['rchild'];
                  b_tree($array['rchild'], $index * 2 + 1, &$tree);
              }
          }
      }
      ?>

    the code is not tested

  2. try

    <?php
    $test = '<td>
        <b><font size="+2" color="#FF0000">Neighboorhood:</font> 
           <font size="+2" color="#0000FF">Greenacre</font></b>
      </td> ';
    $out = preg_replace('/(Neighboorhood:.*?<font.*?)>/s', '\1 what you want to insert>', $test);
    echo $out;
    ?>

  3. try to do all job witk SQL

    <?php
    $r2 = mysql_query("SELECT MAX(progrm_id) AS level FROM user_program WHERE ID='".$usrid."' AND user_status='Active'");
    $buffer_r2 = mysql_fetch_assoc($r2);
    $level_id = $buffer_r2['level'];
    $levels = array(1 => "Professional", "Gold", "Diamond", "Platinum", "Elite");
    $level_name = $levels[$level_id];
    ?> 

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.