Jump to content

PHP Array link to page


Wheelie222

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.