我是PHP新手。我的PHP代碼有問題。在MySQL中,我有我的數據庫是這樣的:php從查詢中匹配的數據庫中獲取所有值
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
其country_name
是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
)
有人能請你告訴我如何從數據庫中獲得這兩個值?任何幫助和建議都將非常可觀。
這是十萬 –
@YourCommonSense鏈接重複請 – Kermit