form dinamico regione provincia comune code example

Example: form dinamico regione provincia comune

<?php

class SelectList
{
	
	protected $conn;
	
		public function __construct()
		{
			$this->DbConnect();
		}
	
		protected function DbConnect()
		{
			include "./config.php";
			
			$this->conn = mysqli_connect($DB_host,$DB_user,$DB_password,$DB_name) OR die("Impossibile connettersi al database");
			mysqli_select_db($this->conn,$DB_name) OR die("Impossibile selezionare il database $db");
			
			return TRUE;
		}
		
		public function ShowRegioni()
		{
			$res = mysqli_query($this->conn,"SELECT * FROM regioni");
			$regioni = '<option value="0">Scegli Regione...</option>';
			
				while($row = mysqli_fetch_array($res))
				{
					$regioni .= '<option value="' . $row['id_reg'] . '">' . utf8_encode($row['nome_regione']) . '</option>';
				}
				
			return $regioni;

			}
		
		public function ShowProvince()
		{
			$res = mysqli_query($this->conn,"SELECT * FROM province WHERE id_reg=$_POST[id_reg]");
			$province = '<option value="0">Scegli Provincia...</option>';
			
				while($row = mysqli_fetch_array($res))
				{
					$province .= '<option value="' . $row['id_pro'] . '">' . utf8_encode($row['nome_provincia']) . '</option>';
					$provincia = $row['nome_provincia'];
				}
				
			return $province;
		}
		
		public function ShowComuni()
		{
			$res = mysqli_query($this->conn,"SELECT * FROM comuni WHERE id_pro=$_POST[id_pro]");
			$comuni = '<option value="0">Scegli Comune...</option>';
			
				while($row = mysqli_fetch_array($res))
				{
					$comuni .= '<option value="' . $row['id_com'] . '">' . $row['cap'] . ' - ' . utf8_encode($row['comune']) . '</option>';
					$comune = $row['comune'];
				}
				
			return $comuni;
		}
}

?>

Tags:

Misc Example