Warning: mysql_fetch_assoc()

Suchfunktion

Erfahrenes Mitglied
Aloah, bzw. Morgen :)

Erstmal vorweg:
Im grossen und ganzen stammt die Vorlage fuer das Templatesystem von Nils Hitze.
Ich habe nur alle Kommentare geloescht weil der source hier sonst viel zu gross wird.

Und los:
Also ich bin auch gerade testweise dabei ein cms zu schreiben, allerdings haenge ich gerade an einem fehler.

Hier die Fehlermeldung:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\foobar\test.php on line 23
(Tjaja.. die misterioese 23.. heil eris diskordia! ;) )

Und hier mein source:


index.php
PHP:
<?php
 include("class_muhkuh.inc.php");

 $mysql["host"] = "127.0.0.1";
 $mysql["user"] = "root";
 $mysql["password"] = "";
 $mysql["database"] = "lalune";

 if(!isset($_GET["id"])) $id = 1;
 if(!isset($id)) $id = $_GET["id"];

 mysql_connect($mysql["host"],$mysql["user"],$mysql["password"]);
 mysql_select_db($mysql["database"]);

 $sql = "SELECT * FROM doc_desc, doc_text "
      . "WHERE doc_desc.c_id = doc_text.id AND doc_text.id = $id";
 $sql_link = "SELECT * doc_text ORDER BY position ASC";

 $_result = mysql_query($sql);
 $_array = mysql_fetch_assoc($_result);
 
 $link = mysql_query($sql_link);
 while ($e = mysql_fetch_assoc($link)) {
  $link   .= '<a href="index.php?id='.$e['id'].'">'.$e['name']."</a><br />\n";
 }
 
 $title     = $_array["title"];
 $sitename  = $_array["name"];
 $css       = $_array["css"];
 $template  = $_array["template"];
 $text      = $_array["text"];
 $date	    = $_array["date"];

 $var_array = array("TITLE" => $title,
 					"SITENAME" => $name,
                    "CSS" => $css,
                    "MAIN" => $text,
					"DATE" => $date,
					"LINK" => $link);

 $tpl = new parser($template, $var_array);
?>


class_muhkuh.inc.php:
PHP:
<?php
 Class parser
 {
  var $template;
  var $temp_content;

  function parser($template, $var_array)
  {
   $this->template = $template;
   $this->temp_content = file($this->template);
   $parsed = $this->rplc($var_array);
   echo(implode("", $this->temp_content));
  }

  function rplc($var_array)
  {
   foreach($var_array as $key => $value)
   {
    $regex['var_name'] = "#{[[:space:]]*?(".strtoupper($key)."){1,}?[[:space:]]*?}#si";
    $this->temp_content = preg_replace($regex['var_name'], $value, $this->temp_content);
   }
  }
 }
?>


content.html (Ausgabeseite)
PHP:
<html>
<head>
<title>{TITLE}</title>
<link rel="Stylesheet" href="{CSS}" type="text/css">
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.Stil1 {color: #000000}
-->
</style>
</head>
<body>
<div align="center">
  <p>&nbsp;</p>
  <table width="700" border="1" class="text">
    <tr>
      <td width="150">&nbsp;</td>
      <td colspan="3">&nbsp;</td>
      <td width="150">&nbsp;</td>
    </tr>
    <tr>
      <td width="150">&nbsp;</td>
      <td colspan="3"><div align="left">{SITENAME}</div></td>
      <td width="150">&nbsp;</td>
    </tr>
    <tr>
      <td width="150">{LINK}</td>
      <td width="5">&nbsp;</td>
      <td>{MAIN}</td>
      <td width="5">&nbsp;</td>
      <td width="150">&nbsp;</td>
    </tr>
    <tr>
      <td width="150">&nbsp;</td>
      <td colspan="3"><div align="right">{DATE}</div></td>
      <td width="150">&nbsp;</td>
    </tr>
    <tr>
      <td width="150">&nbsp;</td>
      <td colspan="3">&nbsp;</td>
      <td width="150">&nbsp;</td>
    </tr>
  </table>
  </div>
</body>
</html>

(Das man die daten von meiner mysql-db etc. sieht juckt mich nich.. is eh nich ans inet angeschlossen ;) )


Also die genaue Fehlerzeile ist in der index.php und zwar die erste zeile der while-schleife
PHP:
while ($e = mysql_fetch_assoc($link)) {
  $link   .= '<a href="index.php?id='.$e['id'].'">'.$e['name']."</a><br />\n";
 }

Aber was ist daran falsch? *grml*
help!
Danke schonmal im Voraus!


//Nachtrag:
Also nochma zum Ablauf der index.php:
Code:
1. Anmelden an datenbank
2. Waehle Datenherkunft aus
3. Speichere Daten + HTML-Code in $link
4. Speicher $link in LINK
 
Zuletzt bearbeitet:
PHP:
$link = mysql_query($sql_link);
while ($e = mysql_fetch_assoc($link)) {
  $link   .= '<a href="index.php?id='.$e['id'].'">'.$e['name']."</a><br />\n";
}
beim ersten Schleifendurchlauf wird $link verändert, dadurch ist es keine gültige MySQL result resource mehr.
 
PHP:
 $link = mysql_query($sql_link);
 while ($e = mysql_fetch_assoc($link)) {
  $muh   .= '<a href="index.php?id='.$e['id'].'">'.$e['name']."</a><br />\n";
 }

Mein aktueller code, alelrdings haargenau der selbe Fehler :(
 
uiuiui.. muss wohl am Rest-Alkohol im Blut gelegen haben :rolleyes:
Danke an euch alle :)

//Nachtrag:
So habs ma ausprobiert.. klappt erste sahne :)
Vielen, vielen dank..
(Man das war nen doofheitsfehler *grins*)
 
Zurück