You are not logged in.

wcf.regNote.message

Manuel

Trainee

  • "Manuel" started this thread

Posts: 64

  • Send private message

1

Saturday, October 14th 2006, 11:40am

Suchen in Tabelle

Hallo zusammen,

ich suche in einer Tabelle meiner Datenbank mit diesem Code:

PHP Source code

1
2
3
4
5
6
7
8
9
10
11
$result2 mysql_query("SELECT " $filmsuchbegriff .  " FROM " $n .  "_filme order by '" $film_sort_nach .  "'");
  while($row2 mysql_fetch_array($result2)) {
     echo '<tr>
      <td class="log" width="30px">' $row2['id']         . '</td>
      <td class="log" width="80px">' $row2['date']       . '</td>
      <td class="log" width="60px">' $row2['time']       . '</td>
      <td class="log" width="350px">' $row2['filmtitel']  . '</td>
      <td class="log" width="80px">' $row2['dauer']      . '</td>
      <td class="log">' $row2['filmart']    . '</td>
    </tr>';
  }


Das klappt auch alles super, solange in der Variablen $filmsuchbegriff ein "*" steht, also nach allem suchen. Aber sobald da aber was anderes steht geht das nicht. Und ich bekomme die Fehler meldung:

Quoted

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\xampp\htdocs\db\suche.php on line 214
Gruß M-Arens

Ephraim

Professional

Posts: 826

Location: coder-board.info

Occupation: Info-Student

  • Send private message

2

Saturday, October 14th 2006, 1:18pm

An dieser Stelle wo du deine Variable stehen hast, können auch nur Spaltennamen der Tabelle stehen.
Versuch mal:
$result2 = mysql_query("SELECT * FROM " . $n . "_filme WHERE `NAMEEINERSPALTE` like '%" . $filmsuchbegriff . "%' order by '" . $film_sort_nach . "'");

wobei du NAMEEINERSPALTE ersetzten muss mit einem Namen der einer Spalte aus der SQL Tabelle.
Also z.b. filmtitel oder filmart

Ciao Ephraim

Manuel

Trainee

  • "Manuel" started this thread

Posts: 64

  • Send private message

3

Monday, October 16th 2006, 10:35am

Ja, das klappt wohl so aber jetzt ist das problem, wenn ich einen "*" eintrage soll ja nach allem gesucht werden was aber nicht mehr klappt.
Gruß M-Arens

Ephraim

Professional

Posts: 826

Location: coder-board.info

Occupation: Info-Student

  • Send private message

4

Monday, October 16th 2006, 11:48am

benutz % anstatt *

;)

Ciao Ephraim

Manuel

Trainee

  • "Manuel" started this thread

Posts: 64

  • Send private message

5

Monday, October 16th 2006, 12:40pm

wo? im Code???
Gruß M-Arens

ralle030583

Beginner

Posts: 51

Location: Neuss

Occupation: FI Anwendungsentwicklung

  • Send private message

6

Monday, October 16th 2006, 1:20pm

* ist % im SQL

z.B. Falls ich meinen Nick in einer Namenstabelle suchen würde,
würde ich nicht 'ralle*' und '*030583' schreiben, sonder mit das ganze mit %.

Source code

1
2
SELECT NAME FROM tab_name WHERE NAME LIKE 'Ralle%';
SELECT NAME FROM tab_name WHERE NAME LIKE '%030583';


Am besten vor abschicken des SQL's * durch % ersetzen, falls du möchtest das man mit * suchen kann.

This post has been edited 3 times, last edit by "ralle030583" (Oct 16th 2006, 1:22pm)


Manuel

Trainee

  • "Manuel" started this thread

Posts: 64

  • Send private message

7

Monday, October 16th 2006, 1:31pm

Wie kann ich das denn in * ändern???
Gruß M-Arens

lichtonkel

Beginner

Posts: 39

Occupation: staat. gepr. Informatiker Multimedia/Studierender

  • Send private message

8

Monday, October 16th 2006, 2:46pm

am einfachsten mit der str_replace() funktion, näheres dazu findest du bei der suchmaschine deiner wahl oder bei php.net ;-)

Lichtonkel

Manuel

Trainee

  • "Manuel" started this thread

Posts: 64

  • Send private message

9

Tuesday, October 17th 2006, 8:39am

Danke
Gruß M-Arens

wcf.user.socialbookmarks.titel