我是 PHP 新手。我的 PHP 代码有问题。在 MySQL 中,我的数据库是这样的:
CREATE TABLE IF NOT EXISTS `propertylocator` (
`store_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`store_name` varchar(255) NOT NULL,
`country_name` varchar(255) NOT NULL,
`state_name` varchar(255) NOT NULL,
`city_name` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL
PRIMARY KEY (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
INSERT INTO `propertylocator` (`store_id`, `store_name`, `country_name`, `state_name`, `city_name`, `address`, `description`) VALUES
(1, 'My property1', 'India', 'uttar pradesh', 'Ghaziabad', 'Pilkhuwa, Uttar Pradesh 245304, India', 'this is demo test','this is dummy description'),
(2, 'My new Property', 'India', 'Maharashtra', 'Thane', 'Kudavali, Maharashtra 421401, India', 'test propery again', 'another dummy property'),
(3, 'Dummy store', 'United Arab Emirates', 'Sharjah', 'Halwan Suburb', 'Al Ghubaiba - Sharjah - United Arab Emirates', 'this is another dummy store','another text with dummy');
现在我想展示所有city_names
who country_name
is India
。为此,我在 phpMyAdmin 中做了一个简单的查询,如下所示:
SELECT `city_name` FROM `ps_storelocator` WHERE `country_name`= 'india'
它向我展示了两个结果
Ghaziabad
Thane
现在,当我试图从我的 php 代码中获取它时。它只显示一个值。代码是这样的
$host = "localhost";
$user = "root";
$pass = "";
$databaseName = "stores";
$tableName = "propertylocator";
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
$result = mysql_query("SELECT `city_name` FROM `propertylocator` WHERE `country_name`= 'india'");
$arrayvalue = mysql_fetch_array($result);
print_r($arrayvalue);
现在我得到这样的价值
Array
(
[0] => Ghaziabad
[city_name] => Ghaziabad
)
有人可以告诉我如何从数据库中获取这两个值吗?任何帮助和建议都将是非常可观的。