Avatar billede schunck Juniormester
03. juli 2007 - 14:00 Der er 3 kommentarer og
1 løsning

Hent informationer via søgning på database

Jeg er ved at lave en søgefunktion via dropdown, hvor jeg sender nogle informationer og får de resultater tilbage der svarer til min forespørgsel.

Jeg er ikke helt sikker på hvordan jeg skal formulere mit problem, men hvordan får jeg min FORM til at virke med resten.

Jeg kunne forestille mig at det var noget med en $_POST, men umiddelbart tror jeg scriptet taler for sig selv.


<?php

require_once "maincore.php";
require_once "subheader.php";
require_once "side_left.php";
include LOCALE.LOCALESET."hold.php";

opentable(Holdoversigt);
echo "<form name='searchform' method='post' action='".FUSION_SELF."'>
<table align='center' cellpadding='0' cellspacing='0' width='100%'>
<td class='tbl' align='left'>".$locale['hold008']."</td>
<td width='5px'>
</td>
<td class='tbl'>".$locale['hold003']."</td>
<td width='5px'>
</td>
<td class='tbl'>".$locale['hold006']."</td>
</tr>
<tr>
<td class='tbl' align='left'><select name='hold_koen'>
    <option name='hold_koen' value='2'>Pige</option>
    <option name='hold_koen' value='1'>Dreng</option>
   
    </select>
</td>
</td>
<td width='10px'>
</td>
<td class='tbl' align='left'><select name='hold_alder'>
    <option name='hold_alder' value='4-6'>4-6</option>
    <option name='hold_alder' value='6-8'>6-8</option>
    <option name='hold_alder' value='8-10'>8-10</option>
    <option name='hold_alder' value='10-12'>10-12</option>
    <option name='hold_alder' value='12-14'>12-14</option>
    <option name='hold_alder' value='14-16'>14-16</option>
    <option name='hold_alder' value='16-18'>16-18</option>
    <option name='hold_alder' value='voksen'>Voksen</option>
    <option name='hold_alder' value='familie'>Familie</option></select>
</td>
<td width='10px'>
</td>

<td class='tbl' align='left'><select name='hold_type'>
    <optgroup label='Konkurrence'>
    <option name='hold_type' value='Grandprix'>Grand Prix</option>
    <option name='hold_type' value='Idraetgymnastik'>Idrætsgymnastik</option>
    <option name='hold_type' value='Springrytme'>Spring / Rytme</option>
    <option name='hold_type' value='RSG'>RSG</option>
    <optgroup label='Motion'>
    <option name='hold_type' value='Motion'>Motionshold</option>
    <option name='hold_type' value='Begynder'>Udviklingshold</option>
    </select>
</td>
<td width='10px'>
</td>
<td class='tbl' align='center'>
<input type='submit' name='search' value='".$locale['hold010']."' class='button'><br>\n";
echo "</td></tr>\n";
echo "</table></form>\n";
closetable();

//Det er her jeg mangler et eller andet til at sætte scriptet igang, og så er jeg heller ikke helt sikker på at nedenstående dbquery er korrekt.
    tablebreak();
opentable($locale['hold011']);
$result = dbquery("SELECT * FROM ".$db_prefix."hold WHERE hold_alder='$holdalder' AND hold_koen='$holdkoen' AND hold_type='$holdtype' ORDER BY hold_nummer ASC");
        while ($data = dbarray($result)) {
           
            echo "<table align='left' cellpadding='0' cellspacing='1' width='100%' class='tbl-border'><tr>\n";
            echo "<td align='left' class='scapmain'>".$data['hold_nummer']." - ".$data['hold_navn']."</td><td align='left' class='scapmain' colspan='2'>".$locale['hold006']." ".$data['hold_type']."</td>\n</tr>";
            echo "<td align='left' class='scapmain'>".$locale['hold003']." ".$data['hold_alder']."</td><td align='left' class='scapmain'>".$data['hold_tid']."</td><td align='left' class='scapmain'>".$data['hold_sted']."</td>\n</tr>";
            echo "<td align='left' colspan='3' class='main-body'>".$data['hold_beskrivelse']."</td>\n</tr>\n</table>";
        }
   
closetable();   
           
require_once "side_right.php";
require_once "footer.php";
?>
Avatar billede intenz Novice
03. juli 2007 - 19:23 #1
Prøv at ændre:

$result = dbquery("SELECT * FROM ".$db_prefix."hold WHERE hold_alder='$holdalder' AND hold_koen='$holdkoen' AND hold_type='$holdtype' ORDER BY hold_nummer ASC");
        while ($data = dbarray($result)) {
           
            echo "<table align='left' cellpadding='0' cellspacing='1' width='100%' class='tbl-border'><tr>\n";
            echo "<td align='left' class='scapmain'>".$data['hold_nummer']." - ".$data['hold_navn']."</td><td align='left' class='scapmain' colspan='2'>".$locale['hold006']." ".$data['hold_type']."</td>\n</tr>";
            echo "<td align='left' class='scapmain'>".$locale['hold003']." ".$data['hold_alder']."</td><td align='left' class='scapmain'>".$data['hold_tid']."</td><td align='left' class='scapmain'>".$data['hold_sted']."</td>\n</tr>";
            echo "<td align='left' colspan='3' class='main-body'>".$data['hold_beskrivelse']."</td>\n</tr>\n</table>";
        }




til:
if (isset($_POST['search'])) {
$result = dbquery("SELECT * FROM ".$db_prefix."hold WHERE hold_alder='".$_POST['hold_alder']."' AND hold_koen='".$_POST['hold_koen']."' AND hold_type='".$_POST['hold_type']."' ORDER BY hold_nummer ASC");
        while ($data = dbarray($result)) {
           
            echo "<table align='left' cellpadding='0' cellspacing='1' width='100%' class='tbl-border'><tr>\n";
            echo "<td align='left' class='scapmain'>".$data['hold_nummer']." - ".$data['hold_navn']."</td><td align='left' class='scapmain' colspan='2'>".$locale['hold006']." ".$data['hold_type']."</td>\n</tr>";
            echo "<td align='left' class='scapmain'>".$locale['hold003']." ".$data['hold_alder']."</td><td align='left' class='scapmain'>".$data['hold_tid']."</td><td align='left' class='scapmain'>".$data['hold_sted']."</td>\n</tr>";
            echo "<td align='left' colspan='3' class='main-body'>".$data['hold_beskrivelse']."</td>\n</tr>\n</table>";
        }
}



Ændringerne ligger i din SQL streng, hvor variablerne er ændret til $_POST og der er indsat if (isset($_POST['search'])) { før SQL'en. Det tjekker om din submit knap (som hedder search) er sendt. Hvis den er kører den SQL'en.
Avatar billede schunck Juniormester
03. juli 2007 - 23:56 #2
Det virkede. så smid et svar og du får nogle point retur
Avatar billede schunck Juniormester
03. juli 2007 - 23:59 #3
Skal lige høre med det samme.

Hvis den nu ikke finder nogle resultater, hvordan får jeg den så til at fortælle at der ikke er noget der passer til forespørgslen???

Jeg er selvfølgelig villig til at oprette en nyt spørgsmål, så der kan gives point på dette også.
Avatar billede intenz Novice
04. juli 2007 - 13:55 #4
Det behøver du ikke, det er meget simpelt.

Du ændrer bare:
$result = dbquery("SELECT * FROM ".$db_prefix."hold WHERE hold_alder='".$_POST['hold_alder']."' AND hold_koen='".$_POST['hold_koen']."' AND hold_type='".$_POST['hold_type']."' ORDER BY hold_nummer ASC");


fil:
$result = dbquery("SELECT * FROM ".$db_prefix."hold WHERE hold_alder='".$_POST['hold_alder']."' AND hold_koen='".$_POST['hold_koen']."' AND hold_type='".$_POST['hold_type']."' ORDER BY hold_nummer ASC");
$num = mysql_num_rows($result);


Og:
        }
}

til:
        }
if ($num == "0") {
echo "Der er ingen resultater der passer til forespørgslen";
}
}
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester