MYSQL/PHP 选择不同
我在另一个页面上调用了这个函数。
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');
它只拉出两个结果。 “2 3”[我之前问过这个问题,但措辞不好。]
I have this function called on another page.
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('');
The table is.
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');
It's only pulling two results. "2 3" [I asked this before but worded it poorly.]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来该查询实际上按其应有的方式提取了 3 个结果。你只是让其中一个离开:
如果你只是删除那一行,或者稍微调整一下,它应该会很好地显示所有内容:
Looks like the query is actually pulling 3 results as it should. You are just letting one of them go:
If you just remove that line, or tweak it a little, it should display everything just fine: