
Geschrieben von
take
(Moderator) am 12.04.2007 um 00:00 Uhr.
Beiträge: 613 /
#1204
Kontakt:
Mailen
|
WWW
<?php
- <?php
- mysql_connect("localhost", "USER", "PASS");
- mysql_select_db("DATABASE");
- $table = "news";
- $spalte = "texte";
- ?>
- ?>
¤ Sollte eigentlich selbst-erklärend sein, Verbindung zum MySQL - Server sowie angabe der Tabelle und Spalte wo gesucht werden soll.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
<form action="" method="post" name="form1">
<strong> Suchbegriff(e)<br>
<input name="suchstring" type="text" id="suchstring" value="<?=$_POST['suchstring'];?>">
</strong>
<br>
<input name="option" type="radio" value="1" checked>
Kompletter String <br>
<input name="option" type="radio" value="2">
Wörter aus dem String
<br>
<input name="search" type="submit" id="search" value="suchen">
</form>
¤ Einfaches Formular, dürfte auch kein Problem darstellen ;)
<?php
- <?php
- mysql_connect("localhost", "USER", "PASS");
- mysql_select_db("DATABASE");
- $table = "news";
- $spalte = "texte";
- ?><form action="" method="post" name="form1">
- <strong> Suchbegriff(e)<br>
- <input name="suchstring" type="text" id="suchstring" value="<?=$_POST['suchstring'];?>">
- </strong>
- <br>
- <input name="option" type="radio" value="1" checked>
- Kompletter String <br>
- <input name="option" type="radio" value="2">
- Wörter aus dem String
- <br>
- <input name="search" type="submit" id="search" value="suchen">
- </form>
- <?php
- if (isset($_POST['search']) && $_POST['search'] == "suchen") {
- if (empty($_POST['suchstring']))
- echo "Sie müssen einen Suchtext eingeben.";
- else {
- $string = htmlentities($string);
- if ($_POST['option'] == 1)
- $string = "'%".$_POST['suchstring']."%";
- else {
- $c = explode(" ", $_POST["suchstring"]);
- $a = count($c);
- $string = "'%".$c[0]."%";
- for ($i=1;$i<$a;$i++) {
- $string .= "' || ".$spalte." LIKE '%".$c[$i]."%";
- }
- }
- $s = mysql_query("SELECT * FROM ".$table." WHERE ".$spalte." LIKE ".$string."'");
- while($r=mysql_fetch_array($s)) {
- echo htmlentities($r[$spalte])."<br>";
- }
- }
- }
- ?>
- ?>
Viele Grüße
"Jeder, der andere kritisiert, muss eine Alternative haben, die er ihnen anbieten kann." - Mo Ti