记一段代码[PHP]迭代读取数据库

记一段代码[PHP]迭代读取数据库


<style>

input, select {
 font-size: 14px;
 color: #333333;
 padding-left:3px;
 background:#f6f6f6;
 border: #CCCCCC 1px solid;}
</style>
<?php
require_once dirname(__FILE__) ."/headers.php";

$i = 0;
  

function category($category_parent_timestamp){
   global $db;
   global $i;
   $result = $db->get("{category_parent_timestamp} == " . $category_parent_timestamp,null,"categories",false,"category_time","desc");
   sort($result);
  
   for($index=0;$index<count($result);$index++){          
     echo "<option>";
     for($x=0;$x<$i;$x++){
       echo "--";
      }      
     echo $result[$index]['category_title'];
     echo "&nbsp;";  
     $sub = $db->get("{category_parent_timestamp} == " .$result[$index]['category_timestamp'],null,"categories",false,"category_time","desc");
     if(count($sub)!=0){
       $i++;
       category($result[$index]['category_timestamp']);//迭代      
       $i--;
     }
     echo "</option>";
   }
   
}    
 
echo "<select>";
category("0"); 
echo"</select>";
?>

你可能感兴趣的:(记一段代码[PHP]迭代读取数据库)