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;
		}
}

?>

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source