我有一个名为ps_megasearch_attributes的数据库。对于我的数据库查询是这样MySQL返回的结果在while循环中显示两次?
CREATE TABLE IF NOT EXISTS `ps_megasearch_attributes` (
`attribute_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`attribute_name` text NOT NULL,
PRIMARY KEY (`attribute_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
--
-- Dumping data for table `ps_megasearch_attributes`
--
INSERT INTO `ps_megasearch_attributes` (`attribute_id`, `attribute_name`) VALUES
(1, 'Color');
我们从数据库中获取值我在PHP
<?php
$attribute_name_fetch = mysqli_query($con,"SELECT `attribute_name` FROM `ps_megasearch_attributes` ORDER BY `attribute_id` DESC LIMIT 1 ");
while($attributes_list=mysqli_fetch_array($attribute_name_fetch)){
foreach($attributes_list as $attribute_name) {
echo $attribute_name;
}
}
?>
这个代码,但这个是显示两次返回结果数组。那么有人可以告诉我该怎么做?任何帮助都将非常可观。
不需要列名和表名的单引号,这可以让你查询问题。通常,单引号仅用于值。 – Yani