Menü mit mySQL!! Was mach ich falsch

hafa

Grünschnabel
Hallo,
hab mir ein Menü Script runtergeladen und angepasst, nur da erscheint ein Fehler!!
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\xampp\xampp\htdocs\m11\dblayer.php on line 17

Warning: asort() expects parameter 1 to be array, null given in E:\xampp\xampp\htdocs\m11\index.php on line 51

Warning: Variable passed to each() is not an array or object in E:\xampp\xampp\htdocs\m11\index.php on line 52

Was mach ich Falsch?

hier das Script!!

index.php
PHP:
<?
// UltraTree v.1.1 by Mike Baikov (mikebmv@hotmail.com)
// this program fetches the categories from your database
// and builds a nice threaded tree ***using only one select***
// yeah, that's right, it saves lots of time
// CONDITIONS OF USE
// you may use it as you like under the following conditions:
// 1) this script is provided AS IS WITHOUT ANY WARRANTY
// 2) you'll keep the notice <!--built by UltraTree v.1.1 http://www.tourbase.ru/zink/-->
// in the HTML output
// 3) you shall rack YOUR brain to solve all problems related
// with UltraTree and related software
// 4) don't say this script is not well documented
//
// UltraTree homepage: http://www.tourbase.ru/zink/

// time benchamrk (optional) start time count
  $timeparts = explode(" ",microtime());
// time benchamrk end

// dblayer.php3 is my DB-abstraction layer
include "dblayer.php";
// include a nice header
include "header.php";

// this function select the data from a DB and passes it to makebranch
// this line: $partable[$catid][$parcat]=$name;
// is used for buildparent
// you may delete it if you don't use buildparent
// this will save memory and time
function maketree($rootcatid,$sql,$maxlevel){
// $sql is the sql statement which fetches the data
// you MUST keep this order:
// 1) the category ID, 2) the parent category ID, 3) the name of the category
         $result=dbquery($sql);
                 while(list($catid,$parcat,$name)=dbfetch($result)){
                 $table[$parcat][$catid]=$name;
                 $partable[$catid][$parcat]=$name;
                 };
         $result=buildparent($rootcatid,$table,$partable)."<br>";
         $result.=makebranch($rootcatid,$table,0,$maxlevel);
         // please keep this notice
         $result.="<!--built by UltraTree v.1.1 http://www.tourbase.ru/zink/-->\n";
         RETURN $result;
}

// this function builds the branches,
// sorting them in alphabetical order
function makebranch($parcat,$table,$level,$maxlevel){
         $list=$table[$parcat];
         asort($list); // here we do the sorting
                while(list($key,$val)=each($list)){
                      // do the indent
                      if ($level=="0"){
                      $output="<img src=se.gif width=12 height=12>";
                      }else{
                      $width=($level+1)*24;
                      $output="<img src=e.gif width=$width height=12>";
                      };
                // the resulting HTML - feel free to change it
                // $level is optional
                $result.= "$output <a href=index.php?catid=$key>$val</a> ($level)<br>\n";
                      if ((isset($table[$key])) AND (($maxlevel>$level+1) OR ($maxlevel=="0"))){
                      $result.= makebranch($key,$table,$level+1,$maxlevel);
                      };
                };
         RETURN $result;
}

// this function makes the list of the parent categories
// this function is optional
function buildparent($catid,$table,$partable){
         if ($catid!=0){
         $list=$partable[$catid];
         $result=each($list);
         $output="<a href=index.php?catid=$result[0]>$result[1]</a> / ";
         $output=buildparent($result[0],$table,$partable).$output;
         };
         RETURN $output;
}

// set the default category
if (!isset($catid)){
$catid=0;
};
// build and print the tree NOTE: $maxlevel is the maximum level,
// set to 0 to show all levels
$maxlevel=0;
print maketree($catid,"SELECT catid,parcat,name FROM tree order by parcat",$maxlevel);

// time benchamrk (optional): end time count, get benchmark result
  $starttime = $timeparts[1].substr($timeparts[0],1);
  $timeparts = explode(" ",microtime());
  $endtime = $timeparts[1].substr($timeparts[0],1);
  $totaltime=bcsub($endtime,$starttime,6);
print "<font size=\"1\">UltraTree built in $totaltime sec</font>";
// time benchmark end
?>


dblayer.php
PHP:
<?
// MySQL layer
if (!isset($conid)){
function dbconnect (){
$mysql=mysql_connect("localhost", "****", "******");
mysql_select_db("******");
return $mysql;
}

function dbquery ($sql){
GLOBAL $conid;
$result=mysql_query($sql,$conid);
return $result;
}

function dbfetch ($result){
if ($row=mysql_fetch_array($result)){
return $row;
} else {
return false;
};
}

function dbrows ($result){
$num=mysql_num_rows($result);
return $num;
};

function dbfree ($result){
mysql_free_result($result);
}

function dbclose ($conid){
GLOBAL $conid;
mysql_close($conid);
}
$conid=dbconnect();
};
?>


header.php
PHP:
<html>
<head>
<title>UltraTree</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<style type="text/css">
<!--
td {  font-family: Arial, Helvetica, sans-serif; font-size: 10pt}
body {  font-family: Arial, Helvetica, sans-serif; font-size: 10pt}
a {  text-decoration: none}
a:hover {  text-decoration: underline}
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" vlink="#0000CC">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr bgcolor="#000099">
    <td><b><font color="#FFFFFF">Test</font></b></td>
  </tr>
    <tr bgcolor="#CCCCCC">
    <td>
   </tr>
  </table>

make.php
PHP:
<?
// this script will create a table called TREETEST
// and populate it with 500 lines of random data
// ...just to benchmark

// CONDITIONS OF USE
// you may use it as you like under the following conditions:
// 1) this script is provided AS IS WITHOUT ANY WARRANTY
// 2) you'll keep the notice <!--built by UltraTree v.1.1 http://www.tourbase.ru/zink/-->
// in the HTML output
// 3) you shall rack YOUR brain to solve all problems related
// with UltraTree and related software
// 4) don't say this script is not well documented

include "dblayer.php";
include "header.php";
$sql="CREATE TABLE treetest (   catid mediumint(5) NOT NULL auto_increment, parcat mediumint(5) NOT NULL,   name varchar(50) NOT NULL,   UNIQUE catid (catid))";
dbquery($sql);

srand((double)microtime()*1000000);
for ($i=1;$i<=500;$i++){
if ($i>20){
$parcat=rand(1,100);
}else{
$parcat=0;
};
$sql="INSERT INTO treetest (catid,parcat,name) VALUES ('$i','$parcat','CATEG $i-$parcat')";
dbquery($sql);
print "$i - $parcat<br>";
};
?>

Danke in vorraus
 
Schau Dir mal die Scripte genau an:

in der make.php erstellst Du eine Tabelle "treetest" und in der index.php fragst Du die Tabelle "tree" ab. ;)

PHP:
CREATE TABLE treetest ......


SELECT catid,parcat,name FROM tree .....
 
Zurück