简体   繁体   中英

How can I use the data I get from my database using PHP, MySQL, Bootstrap?

My question simple Ex. Country, --> State --> City.

How to make like above this, I need to implement in my website. Like dropdown menu.

After the select the City its redirect to the City peoples list.

How its will make ???

// Create Connection
            $conn = mysqli_connect($servername, $username, $password, $dbname);

            // Check connection
            if (!$conn) {
                trigger_error("Connection failed: " . mysqli_connect_error());

            }
            //Run Query
            $stmt = "SELECT * FROM country";
            $result = mysqli_query($conn,$stmt) or die(mysqli_error($conn));
            while(list($category) = mysqli_fetch_row($result)){
                echo '<option value="'.$category.'">'.$category.'</option>';
            }


            mysqli_close($conn);
            ?>

            </select>

Any other alternative code ?

mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified

<?php
$dbname = "myDB";
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn ){

die('Could not connect: ' . mysql_error());

}
$sql = 'SELECT * FROM country';
mysql_select_db($dbname);

$retval = mysql_query( $sql, $conn );
if(! $retval ){
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)){

   echo '<option value="'.$row["id"].'">'.$row["name"].'</option>';
} 
mysql_close($conn);
?>  

http://php.net/manual/en/function.mysql-query.php

example http://www.tutorialspoint.com/mysql/mysql-select-query.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM