我有这个功能在另一个页面上调用。MYSQL/PHP SELECT DISTINCT
function adminnav(){
$pagewcoms = mysql_query("SELECT DISTINCT pageid FROM comments") or die(mysql_error());
$idnavrow = mysql_fetch_row($pagewcoms);
while ($itest = mysql_fetch_row($pagewcoms)) {
echo "$itest[0] <br />";
}
}
adminnav('');
的表看起来像这样
CREATE TABLE `comments` (
`commentid` int(5) NOT NULL auto_increment,
`pageid` int(5) NOT NULL default '0',
`name` text NOT NULL,
`email` text NOT NULL,
`comment` text NOT NULL,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`commentid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=481 ;
INSERT INTO `comments` VALUES(480, 1, '3', '3', '3', '2011-09-13 22:43:06');
INSERT INTO `comments` VALUES(479, 1, '2', '2', '2', '2011-09-13 22:43:01');
INSERT INTO `comments` VALUES(476, 1, '1', '1', '1', '2011-09-13 17:22:49');
INSERT INTO `comments` VALUES(477, 2, 'taylordcraig', '[email protected]', 'this is page two', '2011-09-13 17:26:09');
INSERT INTO `comments` VALUES(478, 3, 'this is page3', 'this is page3', 'this is page3', '2011-09-13 22:28:59');
我的问题是功能打印 “阵列 阵” 我可以处理数据,但不应该有3个不同的结果? 这是我去过的最近的。这个想法是搜索表格并找到带有评论的页面,我将在后面列出链接。
所以我在寻找的结果将是
“1 3”
预先感谢您。
编辑:
对不起,我措辞不好我的问题。 porlem不是“阵列阵列”,它只有两个。我可以让它显示,但没关系。 我仍然只有“2 3”显示,如前所述,我只有两个阵列数据。
[* *我,我我不得不现在又重新问这个?]
不应该是'$ itest [0]'? 'mysql_fetch_row'返回一个枚举数组。 'mysql_fetch_array'会得到关联数组。对? – Farray
@Farray是的,你是对的,编辑。 – xdazz
我重申了我的问题,但措辞更好。我知道[0]它只是拉了两个。 [我reasked http://stackoverflow.com/questions/7412157/mysql-php-select-distinct] – Taylor