Immer selbe Daten

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Immer selbe Daten

    Hiho,

    bitte nicht schlagen, ich bin noch beginner

    Also ich versuche mich gerade daran einen kleinen onlinekatalog fürs intranet zu machen. eigentlich läuft das alles wunderbar, nur mit der suche hab ich so meine probs, ich bekomme immer die gleiche ausgabe wenn ich alles ausgeben will.
    Ich denke mal das ich da einen gravierenden denkfehler oder auch ein wissensmangeldes Problem habe.

    Hier mal der ganze ramsch aus der such datei:
    PHP-Code:
    <?php
    error_reporting
    (8);
    include(
    "./conf/config.php");

    $eanpic ="pic.gif";
    $bildpic ="pic.gif";

    $db_con mysql_connect($dbhost$dbuser$dbpass) or die(mysql_error());
          
    mysql_select_db($dbname) or die(mysql_error());

    if (!isset(
    $ansearch)) $ansearch "";
    else 
    $ansearch "".mysql_escape_string($ansearch);

    if (
    $ansearch== "*") {
    $ansearch  "%%";
    }
    $squery    mysql_query("SELECT * FROM $dbtable WHERE art_nr LIKE '$ansearch'") or die(mysql_error());
    $rsquery_1 mysql_fetch_array($squery);
    $numberall mysql_numrows($squery);
    $x=0;

    $artikel    nl2br ($rsquery_1['artikel']);
    $art_nr     $rsquery_1['art_nr'];
    $abmessung  $rsquery_1['abmessung'];
    $verpackung $rsquery_1['verpackung'];
    $eancode    $rsquery_1['eancode'];
    $eanbild    $rsquery_1['eanbild'];
    $bild       $rsquery_1['bild'];
    $preis      $rsquery_1['preis'];
    $waehrung   $rsquery_1['waehrung'];

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>online Katalog</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form name="ansform" method="get"  action="search.php">
    <table>
    <tr>
        <td><b>Artikel Nr.</b></td>
        <td><input type="text" name="ansearch">
        <input type="submit" name="" value="Suchen">
        </td>
    </tr>
    </table>
    </form>
    <?php
    if ($ansearch== "") {
    echo 
    "<b><u>Keine Eingabe erfolgt!</b></u>\n";
    } else {
    if (
    $numberall== 0) {
    echo 
    "<b><u>Leider nichts gefunden!</b></u>\n";
    } else {
    ?>
    <table width="<? echo $atabwith ?>" border="<? echo $aborder ?>" bordercolor="<? echo $abordercol ?>" cellspacing="0" cellpadding="2" align="<? echo $aformloc ?>">
        <tr>
        <td><b><a href="#"><font size="1" color="<? echo $sortlcolor ?>">ARTIKEL</font></a></b></td>
        <td><b><a href="#"><font size="1" color="<? echo $sortlcolor ?>">ART_NR</font></a></b></td>
        <td><b><a href="#"><font size="1" color="<? echo $sortlcolor ?>">ABMESSUNG</font></a></b></td>
        <td><b><a href="#"><font size="1" color="<? echo $sortlcolor ?>">VERPACKUNG</font></a></b></td>
        <td><b><a href="#"><font size="1" color="<? echo $sortlcolor ?>">EANCODE</font></a></b></td>
        <td><b><!--<a href="<? echo $PHP_SELF; ?>?sortby=eanbild&startLimit=<? echo $startLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>">EANBILD</font></a>--><font size="1" color="<? echo $sortlcolor ?>">EANBILD</b></td>
        <td><b><!--<a href="<? echo $PHP_SELF; ?>?sortby=bild&startLimit=<? echo $startLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>">BILD</font></a>--><font size="1" color="<? echo $sortlcolor ?>">BILD</b></td>
        <td><b><a href="#"><font size="1" color="<? echo $sortlcolor ?>">PREIS</font></a></b></td>
        </tr>
    <?php
            
    while ($x<$numberall)
            {
                if ((
    $x%2)==0) { $bgcolor="$tabbg1"; } else { $bgcolor="$tabbg2"; }
                
    echo 
    "<tr bgcolor=\"$bgcolor\" height=\"30\">";
    echo 
    "<td width=\"$tdwidth1\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$artikel</font>&nbsp;</td>";
    echo 
    "<td width=\"$tdwidth2\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$art_nr</font>&nbsp;</td>";
    echo 
    "<td width=\"$tdwidth3\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$abmessung</font>&nbsp;</td>";
    echo 
    "<td width=\"$tdwidth4\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$verpackung</font>&nbsp;</td>";
    echo 
    "<td width=\"$tdwidth5\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$eancode</font>&nbsp;</td>";

           if (
    $eanbild== "0") {
        
    $eanpic "nopic.gif";
        }
    echo 
    "<td width=\"$tdwidth6\"><a href=\"#\" onclick=\"JavaScript:window.open('eanpic.php?pic=$eanbild','Bild','width=600,height=550,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=200,left=300');\"><img src=\"$eanpic\" border=\"0\" align=\"top\" valign=\"left\"></a></td>";

        if (
    $bild== "00") {
        
    $bildpic "nopic.gif";
    }
    echo 
    "<td width=\"$tdwidth7\"><a href=\"#\" onclick=\"JavaScript:window.open('picture.php?pic=$bild','Bild','width=600,height=550,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=200,left=300');\"><img src=\"$bildpic\" border=\"0\" align=\"top\" valign=\"left\"></a></td>";
    echo 
    "<td width=\"$tdwidth8\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$preis</font>&nbsp;<b>$waehrung</b></td>";
    echo 
    "</tr>\n";

    $x++;
        }
    ?>
    </table>
    <?php
    }
    }
    mysql_close($db_con);
    ?>
    </body>
    </html>
    Zuletzt geändert von Harley; 29.01.2003, 19:22.

  • #2
    DB-Abfrage: OK
    Anzahl Datensätze abfragen: OK
    1. Datensatz holen: na gut
    while-Schleife: meinetwegen
    weitere Datensätze nicht holen: Nicht OK

    lösung
    PHP-Code:
    ...
    $squery    mysql_query("SELECT * FROM $dbtable WHERE art_nr LIKE '$ansearch'") or die(mysql_error());
    $numberall mysql_numrows($squery);
    ...
    if (
    $ansearch== "")
      echo 
    "<b><u>Keine Eingabe erfolgt!</b></u>\n";
    else if (
    $numberall== 0)
        echo 
    "<b><u>Leider nichts gefunden!</b></u>\n";
    if (
    $numberall>0)
    {
        
    //Tabellenkopf ausgeben (<table>....)
          
    for($x=0;$x<$numberall;$x++)
        {
            
    $rsquery_1 mysql_fetch_array($squery);         
            echo 
    "<tr bgcolor=\"$bgcolor\" height=\"30\">";
            echo 
    "<td width=\"$tdwidth1\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$artikel</font>&nbsp;</td>";
            echo 
    "<td width=\"$tdwidth2\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$art_nr</font>&nbsp;</td>";
            echo 
    "<td width=\"$tdwidth3\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$abmessung</font>&nbsp;</td>";
            echo 
    "<td width=\"$tdwidth4\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$verpackung</font>&nbsp;</td>";
            echo 
    "<td width=\"$tdwidth5\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$eancode</font>&nbsp;</td>";
               if (
    $eanbild== "0")
                   
    $eanpic "nopic.gif";
            echo 
    "<td width=\"$tdwidth6\"><a href=\"#\" onclick=\"java script:window.open('eanpic.php?  pic=$eanbild','Bild','width=600,height=550,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=200,left=300');\"><img src=\"$eanpic\" border=\"0\" align=\"top\" valign=\"left\"></a></td>";
               if (
    $bild== "00")
                
    $bildpic "nopic.gif";
            echo 
    "<td width=\"$tdwidth7\"><a href=\"#\" onclick=\"java script:window.open('picture.php?  pic=$bild','Bild','width=600,height=550,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=200,left=300');\"><img src=\"$bildpic\" border=\"0\" align=\"top\" valign=\"left\"></a></td>";
            echo 
    "<td width=\"$tdwidth8\">&nbsp;<font size=\"2\" face=\"Arial, Helvetica, sans-serif\" color=\"$datafcolor\">$preis</font>&nbsp;<b>$waehrung</b></td>";
            echo 
    "</tr>\n";
          }
    }
    ... 
    Du musst immer wieder einen neuen Datensatz holen, nicht einmal einen Datensatz holen und denn so oft verwenden wie du insgesamt Datensätze zurückgeliefert bekommen hast
    Zuletzt geändert von mrhappiness; 29.01.2003, 19:48.
    Ich denke, also bin ich. - Einige sind trotzdem...

    Kommentar


    • #3
      Also entweder blicke ich da nun nicht durch wo was hin sollte oder irgendwas haut noch ned so recht hin.

      Kommentar


      • #4
        Kurzanleitung:
        PHP-Code:
        $sql='select lieblingsfarbe, schuhgroesse, AnzahlWale, NochWasDoofes from schwachfugtabelle';
        $result=mysql_query($sql);
        $anzahl_datensaetze=mysql_num_rows($result);
        if (
        $anzahl_datensaetze>0)
        {
            echo 
        '<table><tr><th>Lieblingsfarbe</th><th>Schuhgröße</th><th>Anzahl Wale</th><th>nach was doofes</th></tr>';
            while(
        $datensatz=mysql_fetch_array($result))
                echo 
        '<tr><td>'.$datensatz['lieblingsfarbe'].'<td>
                <td>'
        .$datensatz['schuhgroesse'].'<td>
                <td>'
        .$datensatz['AnzahlWale'].'<td>
                <td>'
        .$datensatz['NochWasDoofes'].'<td></tr>';
            echo 
        '</table>';
        }
        else
            echo 
        'Nix gefunden in dem scheisendreg datenbank'
        Klarer geworden?

        Stell dir das Ergebnis der query als eine Art Stapel Blätter vor.
        mysql_num_rows sagt dir wieviel Blätter der Stapel hat.
        mysql_fetch_array sagt dir was auf dem obersten Blatt steht und legt es beiseite.
        Ein zweiter Aufruf von mysql_fetch_array sagt dir, was auf dem jetzt obersten Blatt (war vorher das zweite von oben) steht und legt es beiseite
        ...
        Zuletzt geändert von mrhappiness; 29.01.2003, 20:17.
        Ich denke, also bin ich. - Einige sind trotzdem...

        Kommentar


        • #5
          Ok ich glaube es wird mir nun klarer mit der scheisendreck datenbank

          ich werd mal was essen und dann versuch ichs weiter.

          Danke Dir erstmal

          Kommentar

          Lädt...
          X