mi fa fare la scelta ma non riesco a far visualizzare i risultati delle scelte.
ecco il codice che sto usando e che sembra funzionare:
<?php
/*session_start();*/
class OptionMenu
{
var $conn;
var $page;
function OptionMenu()
{
$this->page = basename($_SERVER['PHP_SELF']);
$this->DbConnectAndSelect();
$this->ParsingAction();
}
function DbConnectAndSelect()
{
include "../OLD/conn.php";
$this->conn = @mysql_connect($host,$username,$password) OR
die("Impossibile connettersi al server");
@mysql_select_db($db, $this->conn) OR
die("Impossibile selezionare il database");
}
function JsHeader()
{
echo '<SCRIPT language=JavaScript>
<!--
function goSelect(daform)
{
with(daform)
{
top.window.location=options[selectedIndex].value;
}
}
//-->
</SCRIPT>
';
}
function ShowRegioni()
{
if(isset($_SESSION['Manufacturer']))
{
$marca = $_SESSION['Manufacturer'];
}
else
{
$marca = "Seleziona una marca";
}
$sql = "SELECT distinct Manufacturer FROM IT_Trade";
$res = mysql_query($sql, $this->conn);
echo '<form>
<select onchange="goSelect(this)" size="1">
<option>' . $marca . '</option>
';
while($row = mysql_fetch_array($res))
{
if($row['Manufacturer'] != $marca)
{
echo '<option value="' . $this->page . '?Manufacturer=' . $row['ID'] . '&action=ModelNo&Manufacturer=' . $row['Manufacturer'] . '">' . $row['Manufacturer'] . '</option>
';
}
}
echo '</select>
</form>
';
}
function ShowProvince()
{
if(isset($_SESSION['ModelNo']))
{
$modello = $_SESSION['ModelNo'];
}
else
{
$modello = 'Seleziona modello';
}
echo '<form>
<select onchange="goSelect(this)" size="1">
<option>' . $modello . '</option>
';
if($marca = $this->SelectProvincia())
{
$sql = "SELECT ModelNo FROM IT_Trade WHERE Manufacturer='$marca'";
$res = mysql_query($sql, $this->conn);
while($row = mysql_fetch_array($res))
{
if($row['ModelNo'] != $modello)
{
echo '<option value="' . $this->page . '?ModelNo=' . $row['ID'] . '&action=end&ModelNo=' . $row['ModelNo'] . '">' . $row['ModelNo'] . '</option>
';
}
}
}
echo '</select>
</form>
';
}
function ShowComuni()
{
if(isset($_SESSION['Wattage']))
{
$watt = $_SESSION['Wattage'];
}
else
{
$watt = 'Seleziona un Wattage';
}
echo '<form>
<select onchange="goSelect(this)" size="1">
<option>' . $watt . '</option>
';
if($_GET['ModelNo'])
{
$sql = "SELECT Wattage FROM IT_Trade WHERE ModelNo='$_GET[ModelNo]'";
$res = mysql_query($sql, $this->conn);
while($row = mysql_fetch_array($res))
{
echo '<option value="' . $this->page . '?Wattage=' . $row['ID'] . '&action=end&Wattage=' . $row['Wattage'] . '">' . $row['Wattage'] . '</option>
';
}
}
echo '</select>
</form>
';
}
function SelectProvincia()
{
if(!$_GET['Manufacturer'] AND !$_SESSION['Manufacturer'])
{
return FALSE;
}
else
{
if($_GET['Manufacturer'])
{
return $_GET['Manufacturer'];
}
else
{
$sql = "SELECT Manufacturer FROM IT_Trade WHERE Manufacturer='$_SESSION[Manufacturer]'";
$res = mysql_query($sql, $this->conn);
$row = mysql_fetch_array($res);
return $row['ID'];
}
}
}
function ParsingAction()
{
if(isset($_GET['action']))
{
if($_GET['action'] == 'ModelNo')
{
$_SESSION['Manufacturer'] = $_GET['Manufacturer'];
unset($_SESSION['ModelNo']);
unset($_SESSION['Wattage']);
}
if($_GET['action'] == 'Wattage')
{
$_SESSION['ModelNo'] = $_GET['ModelNo'];
unset($_SESSION['Wattage']);
}
if($_GET['action'] == 'end')
{
$_SESSION['ModelNo'] = $_GET['ModelNo'];
$_SESSION['Wattage'] = $_GET['Wattage'];
echo 'Marca: ' . $marca . '<br>Modello: ' . $_SESSION['ModelNo'] . '<br>Lampada: ' . $_SESSION['Wattage'];
/*header("Location: result.php");
die;*/
}
}
}
}
?>