Wheelie222 Posted November 3, 2010 Share Posted November 3, 2010 Hello all, I am working on a webpage which needs to be finished Friday so I am a bit stressing out, hence this post. I have made the following script: // Uitkomst van POST waardes echo"<pre>"; print_r($_POST); echo"</pre>"; // LET OP: De tabel "test_optie" is niet compleet gevuld en daarom werkt het script alleen als je start bij categorie 1. // Het is dus GEEN fout in de script, alleen de database is niet helemaal gevuld kostte me teveel tijd! echo" <html> <head> <style> select {float:left;width:250px;margin:0 5px 0 0;} </style> </head> <body> <form name='form' action='chainselect.php' method='post' /> <select name='veld1' onChange='document.form.submit()'> "; // Data opvragen $sql_categorie = mysql_query("SELECT * FROM plaatsnaam ORDER BY id") or die (mysql_error()); // Counter $a = 0; // Standaard geselecteerd echo"<option value='0' selected>Selecteer een plaats</option>"; while($row_categorie = mysql_fetch_array($sql_categorie)){ $a++; echo"<option value='$row_categorie[id]' ";if($_POST[veld1] == "$a"){echo"selected";}echo">$row_categorie[naam]</option>"; } echo" </select> <select name='veld2' onChange='document.form.submit()'> "; // Data opvragen $sql_rubriek = mysql_query("SELECT * FROM branche WHERE catid = '$_POST[veld1]'") or die (mysql_error()); $ant_rubriek = mysql_num_rows($sql_rubriek); // Huidige id veld2 om zodoende huidig veld te selecteren indien gewijzigd if(isset($_POST[veld2])){ $b = "$_POST[veld2]"; } // Als er geen data gevonden is dan de onderstaande option laten tonen. if($ant_rubriek <= 0){ echo"<option value='0'>-</option>"; } else{ // Standaard geselecteerd echo"<option value='0' selected>Selecteer een branche</option>"; while($row_rubriek = mysql_fetch_array($sql_rubriek)){ echo"<option value='$row_rubriek[id]' ";if($_POST[veld2] == "$row_rubriek[id]"){echo"selected";}echo">$row_rubriek[naam]</option>"; } } echo" </select> <select name='veld3' onChange='document.form.submit()'> "; // Data opvragen $sql_optie = mysql_query("SELECT * FROM filiaal WHERE catid = '$_POST[veld1]' AND rubid = '$_POST[veld2]'") or die (mysql_error()); $ant_optie = mysql_num_rows($sql_optie); // Huidige id veld3 om zodoende huidig veld te selecteren indien gewijzigd if(isset($_POST[veld3])){ $c = "$_POST[veld3]"; } // Als er geen data gevonden is dan de onderstaande option laten tonen. if($ant_optie <= 0){ echo"<option value='0'>-</option>"; } else{ // Standaard geselecteerd echo"<option value='0' selected>Selecteer een filiaal</option>"; while($row_optie = mysql_fetch_array($sql_optie)){ echo"<option value='$row_optie[id]' ";if($_POST[veld3] == "$row_optie[id]"){echo"selected";}echo">$row_optie[naam]</option>"; } } echo" </select> </form> </body> </html> "; ?> What I need now is the results shown linked to a page. U can see the dropdowns in action here: www.inventar.nl/chainselect.php For example: In the first dropdown I select Groningen, in the 2nd drop I select Groningen, Restaurant and in the 3rd Groningen, Restaurant, Ni Hao Wok. This gives me the following: Array ( [veld1] => 1 [veld2] => 2 [veld3] => 3 ) Now I have a page named nihao.php, this page needs to be linked to this array result. So if I do the above dropdowns it needs to open nihao.php Can anyone help me with this problem? I am really confused! Thanks in advance! Wheelie Link to comment https://forums.phpfreaks.com/topic/217688-php-array-link-to-page/ Share on other sites More sharing options...
The Little Guy Posted November 3, 2010 Share Posted November 3, 2010 This: echo"<pre>"; print_r($_POST); echo"</pre>"; To this: switch($_POST['veld3']){ case 3: header("location: nihao.php"); exit; break; case 4: header("location: bacchus.php"); exit; break; } Link to comment https://forums.phpfreaks.com/topic/217688-php-array-link-to-page/#findComment-1130007 Share on other sites More sharing options...
Wheelie222 Posted November 3, 2010 Author Share Posted November 3, 2010 Hey Little Guy, I have done as you said. Now I used: <?php include 'chainselect.php'; ?> at the page that needed the dropdowns and I get the following error: Warning: Cannot modify header information - headers already sent by (output started at /home/inventar/domains/inventar.nl/public_html/pages/applicatie.php:13) in /home/inventar/domains/inventar.nl/public_html/pages/chainselect.php on line 15 I have never had this one before. Could you tell how I can solve it? Thanks again! Link to comment https://forums.phpfreaks.com/topic/217688-php-array-link-to-page/#findComment-1130014 Share on other sites More sharing options...
Wheelie222 Posted November 3, 2010 Author Share Posted November 3, 2010 SOLVED! I cant send data to server twice so I switched: switch($_POST['veld3']){ case 3: header("location: nihao.php"); exit; to switch($_POST['veld3']){ case 3: echo "<script type='text/javascript'>window.location='nihao.php';</script>"; exit; Link to comment https://forums.phpfreaks.com/topic/217688-php-array-link-to-page/#findComment-1130016 Share on other sites More sharing options...
The Little Guy Posted November 3, 2010 Share Posted November 3, 2010 remember that, that won't work if a user has JavaScript disabled also, the reason you got that error was because data was already passed to the browser, so header() has to go before any echo/print or any html and/or whitespace. Link to comment https://forums.phpfreaks.com/topic/217688-php-array-link-to-page/#findComment-1130021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.