Wo ist denn nun die Suchfunktion?

RageNo1

Erfahrenes Mitglied
Hallo,
ich möchte meinen Usern gerne eine Suchfunktion bieten.
Es gibt unter dem Archiv eine, bei der allerdings nur der Newstitle durchsucht wird
dementsprechend aufgelistet wird. Nun möchte ich aber das auch der news_text
durchsucht wird. Leider finde ich einfach nicht den Teil bei dem die Suche
durchgeführt wird.

Hier der Teil in dem Archiv mit der Funktion showSearch:
PHP:
<?php
// Das hier ist die Suchfunktion

    if (!function_exists("showSearch")) {
    function showSearch() {

        global $extension,
               $options,
               $styledata,
               $PHP_SELF,
               $QUERY_STRING;
        require("config.inc".$extension);

        $search_template = $styledata['tpl_search'];
        $monthname = array('Januar', 'Februar', 'M&auml;rz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
        $monthname2 = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
        $thismonth = date("n", time());
        $thisyear = date("Y", time());
        $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
        $authordata = $dbconn->fetchMultiple("SELECT * FROM $usertable ORDER BY id ASC");
        $categorydata = $dbconn->fetchMultiple("SELECT * FROM $categorytable ORDER BY id ASC");
        $close = $dbconn->close(); 
        
        $form_month = "\t      <select name=\"m\">\r\n";
        $form_month = $form_month."\t\t<option value=\"\" selected=\"selected\"></option>";
        for ($month = 1; $month <= 12; $month++) {
            $select = "";
          //  if ($month == $thismonth) { $select = " selected"; }
            $form_month = $form_month."\t\t<option value=\"".$monthname2[$month - 1]."\"$select>".$monthname[$month - 1]."</option>\r\n";
        }
        $form_month = $form_month."\t      </select>";

        $form_year = "\t      <select name=\"y\">\r\n";
        $form_year = $form_year."\t\t<option value=\"\" selected=\"selected\"></option>";
        for ($year = 2001; $year <= $thisyear; $year++) {
            $select = "";
          //  if ($year == $thisyear) { $select = " selected"; }
            $form_year = $form_year."\t\t<option value=\"$year\"$select>$year</option>\r\n";
        }
        $form_year = $form_year."\t      </select>";

        $form_author = "\t      <select name=\"a\">\r\n";
        $form_author = $form_author."\t\t<option value=\"\" selected=\"selected\"></option>\r\n";
        foreach ($authordata as $key=>$elem) {
            $form_author = $form_author."\t\t<option value=\"$elem[id]\">$elem[username]</option>\r\n";
        }
        $form_author = $form_author."\t      </select>\r\n";

        $form_category = "\t      <select name=\"c\">\r\n";
        $form_category = $form_category."\t\t<option value=\"\" selected=\"selected\">Alle Kategorien</option>\r\n";
        foreach ($categorydata as $key=>$elem) {
            if (($elem['internal'] != 1) && ($elem['id'] > 2)) {
                $form_category = $form_category."\t\t<option value=\"$elem[id]\">$elem[name]</option>\r\n";
            }
        }
        $form_category = $form_category."\t      </select>\r\n";
        
        $form_order = "\t      <select name=\"o\">\r\n";
        $form_order = $form_order."\t\t<option value=\"ASC\">Älteste zuerst</option>\r\n";
        $form_order = $form_order."\t\t<option value=\"DESC\" selected=\"selected\">Neuste zuerst</option>\r\n";
        $form_order = $form_order."\t      </select>\r\n";

        $form_submit = "<input type=\"submit\" class=\"submit\" value=\"Suchen!\" />";
        $form_string = "<input size=\"22\" type=\"text\" name=\"s\" />";
        print "<form action=\"".$PHP_SELF.$QUERY_STRING."&amp;show=archive\" method=\"post\">\r\n"; 
        $search_template = str_replace("{string}", $form_string, $search_template);
        $search_template = str_replace("{month}", $form_month, $search_template);
        $search_template = str_replace("{year}", $form_year, $search_template);
        $search_template = str_replace("{author}", $form_author, $search_template);
        $search_template = str_replace("{category}", $form_category, $search_template);
        $search_template = str_replace("{order}", $form_order, $search_template);
        $search_template = str_replace("{submit}", $form_submit, $search_template);
        if ($options['php_allowed']) {
            $search_template = str_replace('"', '\"', $search_template);
            $search_template = str_replace('?>', 'print "', $search_template);
            $search_template = str_replace('<?php', '"; ', $search_template);
            $search_template = 'print "'.$search_template.'";';
            $search_template = eval($search_template);
        }
        print $search_template;
        print "</form>\r\n";   
    }}
 
Habe ich auch schon festgestellt dachte nur ich hätte was übersehen.
Hier mal das ganze Script inkl. Archivfunktion:

PHP:
<?php
// Das hier ist die Suchfunktion

    if (!function_exists("showSearch")) {
    function showSearch() {

        global $extension,
               $options,
               $styledata,
               $PHP_SELF,
               $QUERY_STRING;
        require("config.inc".$extension);

        $search_template = $styledata['tpl_search'];
        $monthname = array('Januar', 'Februar', 'M&auml;rz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
        $monthname2 = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
        $thismonth = date("n", time());
        $thisyear = date("Y", time());
        $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
        $authordata = $dbconn->fetchMultiple("SELECT * FROM $usertable ORDER BY id ASC");
        $categorydata = $dbconn->fetchMultiple("SELECT * FROM $categorytable ORDER BY id ASC");
        $close = $dbconn->close(); 
        
        $form_month = "\t      <select name=\"m\">\r\n";
        $form_month = $form_month."\t\t<option value=\"\" selected=\"selected\"></option>";
        for ($month = 1; $month <= 12; $month++) {
            $select = "";
          //  if ($month == $thismonth) { $select = " selected"; }
            $form_month = $form_month."\t\t<option value=\"".$monthname2[$month - 1]."\"$select>".$monthname[$month - 1]."</option>\r\n";
        }
        $form_month = $form_month."\t      </select>";

        $form_year = "\t      <select name=\"y\">\r\n";
        $form_year = $form_year."\t\t<option value=\"\" selected=\"selected\"></option>";
        for ($year = 2001; $year <= $thisyear; $year++) {
            $select = "";
          //  if ($year == $thisyear) { $select = " selected"; }
            $form_year = $form_year."\t\t<option value=\"$year\"$select>$year</option>\r\n";
        }
        $form_year = $form_year."\t      </select>";

        $form_author = "\t      <select name=\"a\">\r\n";
        $form_author = $form_author."\t\t<option value=\"\" selected=\"selected\"></option>\r\n";
        foreach ($authordata as $key=>$elem) {
            $form_author = $form_author."\t\t<option value=\"$elem[id]\">$elem[username]</option>\r\n";
        }
        $form_author = $form_author."\t      </select>\r\n";

        $form_category = "\t      <select name=\"c\">\r\n";
        $form_category = $form_category."\t\t<option value=\"\" selected=\"selected\">Alle Kategorien</option>\r\n";
        foreach ($categorydata as $key=>$elem) {
            if (($elem['internal'] != 1) && ($elem['id'] > 2)) {
                $form_category = $form_category."\t\t<option value=\"$elem[id]\">$elem[name]</option>\r\n";
            }
        }
        $form_category = $form_category."\t      </select>\r\n";
        
        $form_order = "\t      <select name=\"o\">\r\n";
        $form_order = $form_order."\t\t<option value=\"ASC\">Älteste zuerst</option>\r\n";
        $form_order = $form_order."\t\t<option value=\"DESC\" selected=\"selected\">Neuste zuerst</option>\r\n";
        $form_order = $form_order."\t      </select>\r\n";

        $form_submit = "<input type=\"submit\" class=\"submit\" value=\"Suchen!\" />";
        $form_string = "<input size=\"22\" type=\"text\" name=\"s\" />";
        print "<form action=\"".$PHP_SELF.$QUERY_STRING."&amp;show=archive\" method=\"post\">\r\n"; 
        $search_template = str_replace("{string}", $form_string, $search_template);
        $search_template = str_replace("{month}", $form_month, $search_template);
        $search_template = str_replace("{year}", $form_year, $search_template);
        $search_template = str_replace("{author}", $form_author, $search_template);
        $search_template = str_replace("{category}", $form_category, $search_template);
        $search_template = str_replace("{order}", $form_order, $search_template);
        $search_template = str_replace("{submit}", $form_submit, $search_template);
        if ($options['php_allowed']) {
            $search_template = str_replace('"', '\"', $search_template);
            $search_template = str_replace('?>', 'print "', $search_template);
            $search_template = str_replace('<?php', '"; ', $search_template);
            $search_template = 'print "'.$search_template.'";';
            $search_template = eval($search_template);
        }
        print $search_template;
        print "</form>\r\n";   
    }}




// Das hier ist das Archiv



    if (!function_exists("showArchive")) {
    function showArchive() {

        global $extension,
               $options,
               $styledata,
               $PHP_SELF,
               $QUERY_STRING;
        require("config.inc".$extension);

        $getvars = array('m', 'y', 's', 'a', 'c', 'p', 'o');
        $postvars = array('m', 'y', 's', 'a', 'c', 'p', 'o');
        foreach ($getvars as $key=>$elem) { if(isset($_GET[$elem])) { $$elem = $_GET[$elem]; } else { $$elem = ""; } }
        foreach ($postvars as $key=>$elem) { if(isset($_POST[$elem])) { $$elem = $_POST[$elem]; } if(!isset($$elem)) { $$elem = ""; } }
 
        $time = "";
        if (($m != "") && ($y != "")) {
            switch ($m) {
                case "January":   $lastday = 31; break;
                case "February":
                    if ($y % 4 == 0) {
                        $lastday = 29;
                    } else {
                        $lastday = 28;
                    }
                    break;
                case "March":     $lastday = 31; break;
                case "April":     $lastday = 30; break;
                case "May":       $lastday = 31; break;
                case "June":      $lastday = 30; break;
                case "July":      $lastday = 31; break;
                case "August":    $lastday = 31; break;
                case "September": $lastday = 30; break;
                case "October":   $lastday = 31; break;
                case "November":  $lastday = 30; break;
                case "December":  $lastday = 31; break;
                default:          $lastday = 30;
            }
            $from = strtotime("1 $m $y 00:00:00");
            $to   = strtotime("$lastday $m $y 23:59:59");
            $time = " time > $from AND time < $to AND";
        } 
        
        $query = "SELECT * FROM $newstable ";
        $submit = "&o=$o";
        if (($o == "") || (($o != "ASC") && ($o != "DESC"))) { $o = "DESC"; }
        if ($p == "") { $p = 1; }
        $query = $query."WHERE";
        if (($time != "") || ($s != "") || ($a != "") || ($c != "")) {
            if ($time != "") { $query = $query.$time; $submit = $submit."&m=$m&y=$y"; }
            if ($a != "") { $query = $query." author_id = $a AND"; $submit = $submit."&a=$a"; }
            if ($c != "") { $query = $query." category = $c AND"; $submit = $submit."&c=$c"; }
            if ($s != "") { $query = $query." news_text LIKE '%$s%' AND news_title LIKE '%$s%' AND"; $submit = $submit."&s=$s"; }
        }
        $query = $query." is_confirmed = 1 AND";
        $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
        $catrows = $dbconn->countRows("SELECT * FROM $categorytable");
        for ($i = 1; $i <= $catrows; $i++ ) {
            $categorydata = $dbconn->fetchArray("SELECT * FROM $categorytable WHERE id = $i");
            if ($categorydata['internal'] == 1) {
                $query = $query." category != $i AND";
            }
        }
        if (substr($query, -3, 3) == "AND") { $query = substr($query, 0, -3); } 
//        if (substr($query, -5, 5) == "WHERE") { $query = substr($query, 0, -6); } 
        $query = $query." ORDER BY sticky $o, time $o";
        $view = ($p - 1) * $options['archive_view_num'];
        $rows = $dbconn->countRows($query);
        $newsdata  = $dbconn->fetchMultiple($query." LIMIT $view,$options[archive_view_num]");
        if ($newsdata != "") {
            $max_p_mod =  $rows % $options['archive_view_num'];                
            if ($rows > $options['archive_view_num']) { $max_p = $rows - $max_p_mod; } else { $max_p = $options['archive_view_num']; }
            $max_p = $max_p / $options['archive_view_num'];
            if (($max_p_mod > 0) && ($rows > $options['archive_view_num'])) { $max_p = $max_p + 1; } 
            if ($options['submit_method'] == 1) {
                $pages = "\r\n(<b>$max_p</b>) Seite";
                if ($max_p != 1) { $pages = $pages."n"; }
                $pages = $pages."&nbsp;&nbsp;&nbsp;&nbsp;";
                if ($max_p <= $options['shown_pages']) {
                    for ($i = 1;$i <= $max_p; $i++ ) {
                        if ($i != $p) {
                            $pages = $pages."[<a href=\"".$PHP_SELF.$QUERY_STRING."&amp;show=archive&amp;p=$i$submit\" class=\"smalltext\">$i</a>] \r\n";
                        } else {
                            $pages = $pages."<b>($i)</b> ";
                        }
                    }
                } else {
                    if (($p - 1) > (($options['shown_pages'] - 1) / 2)) {
                        $pages = $pages."\r\n[<a class=\"navi\" href=\"".$PHP_SELF.$QUERY_STRING."&amp;show=archive&amp;p=1$submit\" class=\"smalltext\">&laquo; erste</a>] \r\n";
                    }
                    if (($p - ($options['shown_pages'] - 1) / 2) < 1) { $start = 1; }
                    elseif (($p + ($options['shown_pages'] - 1) / 2) > $max_p) { $start = $max_p - $options['shown_pages'] + 1; }
                    else { $start = ($p - ($options['shown_pages'] - 1) / 2); }
                    for ($i = $start;$i < $start + $options['shown_pages']; $i++ ) {
                        if ($i != $p) {
                            $pages = $pages."\r\n[<a class=\"navi\" href=\"".$PHP_SELF.$QUERY_STRING."&amp;show=archive&amp;p=$i$submit\" class=\"smalltext\">$i</a>] \r\n";
                        } else {
                            $pages = $pages."<b>($i)</b> ";
                        }
                    }
                    if ($p < ($max_p - ($options['shown_pages'] - 1) / 2)) {
                        $pages = $pages."\r\n[<a class=\"navi\" href=\"".$PHP_SELF.$QUERY_STRING."&amp;show=archive&amp;p=$max_p$submit\" class=\"smalltext\">letzte &raquo;</a>] \r\n";
                    }
                }
            } else {
                $page_part = "\t<input type=\"hidden\" name=\"a\" value=\"$a\">\r\n\t<input type=\"hidden\" name=\"y\" value=\"$y\" />\r\n\t<input type=\"hidden\" name=\"m\" value=\"$m\" />\r\n\t<input type=\"hidden\" name=\"c\" value=\"$c\" />\r\n";
                $pages = "\r\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" class=\"comments\">\r\n  <tr>\r\n    <td>";
                $pages = $pages."(<b>$max_p</b>) Seite";
                if ($max_p != 1) { $pages = $pages."n"; }
                $pages = $pages."<br /><br /></td>\r\n    <td>\r\n";
                if ($p > 1) {
                    $pages = $pages."      <form action=\"".$PHP_SELF.$QUERY_STRING."&amp;show=archive\" method=\"post\">\r\n";
                    $pages = $pages.$page_part;
                    $pages = $pages."\t<input type=\"hidden\" name=\"p\" value=\"".($p - 1)."\" />\r\n";
                    $pages = $pages."\t<input class=\"submit\" type=\"submit\" value=\"Vorherige\" />\r\n";
                    $pages = $pages."      </form>\r\n";
                }
                $pages = $pages."    </td>\r\n    <td>\r\n";
                if ($p < $max_p) {
                    $pages = $pages."      <form action=\"".$PHP_SELF.$QUERY_STRING."&show=archive\" method=\"post\">\r\n";
                    $pages = $pages.$page_part;
                    $pages = $pages."\t<input type=\"hidden\" name=\"p\" value=\"".($p + 1)."\" />\r\n";
                    $pages = $pages."\t<input class=\"submit\" type=\"submit\" value=\"&nbsp;&nbsp;Nächste&nbsp;\" />\r\n";
                    $pages = $pages."      </form>\r\n";
                }
                $pages = $pages."    </td>\r\n    <td>\r\n"; 
                $pages = $pages."      <form action=\"".$PHP_SELF.$QUERY_STRING."&show=archive\" method=\"post\" name=\"choosepage\">\r\n";
                $pages = $pages."\t<select name=\"p\" onChange=\"document.choosepage.submit()\">\r\n";
                for ($i = 1; $i <= $max_p; $i++ ) {
                    $select = "";
                    if ($i == $p) { $select = " selected=\"selected\""; }
                    $pages = $pages."\t  <option value=\"$i\"$select>Seite $i</option>\r\n";
                }
                $pages = $pages."\t</select>\r\n";
                $pages = $pages.$page_part;
                if ($max_p > 1) { 
                    $pages = $pages."\t<input class=\"submit\" type=\"submit\" value=\"&nbsp;&nbsp;Go!&nbsp;&nbsp;\" />\r\n";
                }
                $pages = $pages."      </form>\r\n";
                $pages = $pages."    </td>\r\n  </tr>\r\n</table>";
            }
            $archive_template = $styledata['tpl_archive'];
            $archivebit_tpl = $styledata['tpl_archivebit'];
            $alt_color1 = $styledata['alt1_color'];
            $alt_color2 = $styledata['alt2_color'];
            $color_mode = 1;
            $archivedata = "";
            foreach ($newsdata as $key=>$elem) {
                $authordata = $dbconn->fetchArray("SELECT * FROM $usertable WHERE id = $elem[author_id]");
                $categorydata = $dbconn->fetchArray("SELECT * FROM $categorytable  WHERE id = $elem[category]");
                if ($categorydata['internal'] != 1) {
                    if ($options['comments_allowed'] && ($elem['comments'] == 1)) {
                        $countcomments = $dbconn->countRows("SELECT NULL FROM $commentstable WHERE news_id = $elem[id]");
                        $comments = "<a href=\"".$PHP_SELF.$QUERY_STRING."&amp;comments=$elem[id]#newcomment\" class=\"smalltext\">$countcomments Kommentar";
                        if ($countcomments != 1) {
                            $comments = $comments . "e";
                        } 
                    $comments = $comments . "</a>";
                
                    } elseif (!$options['comments_allowed'] || ($elem['comments'] == 0)) {
                        $comments = "<span class=\"smalltext\">Komm. deaktiviert</span>";
                    }
            
                    if ($color_mode == 1) {
                        $color1_output = $alt_color1; $color2_output = $alt_color2; $color_mode = 2;
                    } else {
                        $color2_output = $alt_color1; $color1_output = $alt_color2; $color_mode = 1;
                    }
                    $title = $elem['news_title'];
                    if (strlen($title) > $options['title_cutter']) {
                      $title = substr($title, 0, ($options['title_cutter'] - 8))."...".substr($title, -5, 5);
                    }
                    $title = "<a class=\"navi\" href=\"".$PHP_SELF.$QUERY_STRING."&amp;comments=$elem[id]\" target=\"_self\" class=\"smalltext\">$title</a>";
                    $archivebit = str_replace("{author}", $authordata['username'], $archivebit_tpl);
                    $archivebit = str_replace("{title}", "&nbsp;&nbsp;&nbsp;$title", $archivebit);
                    $archivebit = str_replace("{comments}", $comments, $archivebit);
                    $archivebit = str_replace("{category}", $categorydata['name'], $archivebit);
                    $archivebit = str_replace("{time}", date($options['date_format'], $elem['time']), $archivebit);
                    $archivebit = str_replace("{color1}", $color1_output, $archivebit);
                    $archivebit = str_replace("{color2}", $color2_output, $archivebit);
                    $archivedata = $archivedata.$archivebit;
                }
            }
            $archive_template = str_replace("{pages}", $pages, $archive_template);
            $archive_template = str_replace("{path}", "".$PHP_SELF.$QUERY_STRING."&", $archive_template);
            $archive_template = str_replace("{data}", $archivedata, $archive_template);
            if ($options['php_allowed']) {
                $archive_template = str_replace('"', '\"', $archive_template);
                $archive_template = str_replace('?>', 'print "', $archive_template);
                $archive_template = str_replace('<?php', '"; ', $archive_template);
                $archive_template = 'print "'.$archive_template.'";';
                $archive_template = eval($archive_template);
            }
            print $archive_template;
            $close = $dbconn->close(); 
        } else {
            print "<div align=\"center\" class=\"smalltext\"><b><font color=\"#BF0000\">Fehler:</font> Keine News gefunden!</b></div>";
        }
    }}
?>
 
Zuletzt bearbeitet:
Zurück