DB Abfrage NOT NULL ?

Frankster

Mitglied
Hi!

Mittels Select kann man zw 4 Typen unterscheiden
Kerze
Spiegel
Bild
alle

PHP:
<td><select name="typ">
       	<option value="Kerze" <?php if($typ=='Kerze') echo"selected"; ?>>Kerze
       	<option value="Spiegel" <?php if($typ=='Spiegel') echo"selected"; ?>>Spiegel
       	<option value="Bild" <?php if($typ=='Bild') echo"selected"; ?>>Bild
       	<option value="not null" <?php if($typ==not null) echo"selected"; ?>>alle
    	</select></td>

Kerze, Spiegel oder Bild zu übergeben ist ja nicht schwer. Nur wann ich alle Typen anzeigen lassen will, wird nichts ausgeben :(
PHP:
$SQLString = "SELECT * FROM shop WHERE Typ = '$typ'";

Was passt da nicht ?
Mfg
Frankster
 
wenn du alle Typen ausgeben möchtest, muss du per SQL ausgeben: "select * from shop", das könntest du per if-Abfrage meistern -

PHP:
<td><select name="typ">
           <option value="Kerze" <?php if($typ=='Kerze') echo"selected"; ?>>Kerze
           <option value="Spiegel" <?php if($typ=='Spiegel') echo"selected"; ?>>Spiegel
           <option value="Bild" <?php if($typ=='Bild') echo"selected"; ?>>Bild
           <option value="" <?php if(!$typ ||$typ == "") echo"selected"; ?>>alle
        </select></td>

mit "not null" funktioniert das nicht ganz...
 
oh sorry, dann war mein Posting recht müllig, ich nehms zurück ;)

solangs doch funktioniert würd ichs auch so lassen - never touch a running (or working) system!
 
Nana, es funktioniert eh nicht :-(

Ich hab jetzt zwei IF Abfragen
PHP:
if($typ=='alle')
select * from shop

if($typ!='alle')
select * from Shop where typ=$typ
nur hät ich halt gerne nur eine IF Abfrage :)
 
PHP:
if($typ=='alle') {
select * from shop;
} elseif($typ!='alle') {
select * from Shop where typ=$typ;
}

ich weiß nich, ob es das ist, was du meintest... so wird die if-Abfrage zumindest nur noch einmal durchlaufen...

könntest ne switch-Bed. nehmen, das wär ne Alternative.
 
Zurück