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');
我的问题是函数打印 “大批 大批” 我可以处理数据,但是不应该有 3 个不同的结果吗? 这是我最近的一次。这个想法是搜索表格并找到带有评论的页面,我稍后会将其列为链接。
所以我正在寻找的结果是
“1 2 3”
提前谢谢你。
编辑:
很抱歉我的问题措辞不好。问题不是“数组数组”,而是只有两个。我可以让它显示,但这并不重要。 我仍然只显示“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 looks like this
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');
My problem is the function prints
"array
array"
I can deal with the data, but shouldn't there be 3 distinct results?
This is the closest I've been. The idea is to search the table and find pages with comments, which I will later list as links.
So the result I'm looking for would be
"1
2
3"
thank you in advance.
EDIT:
I'm sorry I worded my question poorly. The porlem isnt "array array" it's that there's only two. I can make it display but it doesnt matter.
I still only have "2 3" displaying, as said before, I only had two array data.
[** me, am I going to have to re-ask this now?]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
应该是
echo "$itest[0]
>";
Should be
echo "$itest[0] <br />";
检查 PHP 文档: http://php.net/manual/en/ function.mysql-fetch-row.php
您不是在获取值,而是在获取数组。您只看到“array array”的原因是因为第一个结果在
$idnavrow = mysql_fetch_row($pagewcoms);
行上“消失”。将您的函数更改为以下内容,我相信您会看到您期望的所有 3 个数字:
Check the PHP docs: http://php.net/manual/en/function.mysql-fetch-row.php
You're not fetching a value, you're fetching an array. The reason you only see "array array" is because the first result is getting "disappeared" on the
$idnavrow = mysql_fetch_row($pagewcoms);
line.Change your function to the following and I'm sure you'll see all 3 numbers you expect:
mysql_fetch_row 返回一个包含该行中所有项目的数组。您应该打印 $itest[0],而不是打印 $itest。
为了清楚起见,您还可以使用 mysql_fetch_assoc 并打印 $itest['pageid'] 。
mysql_fetch_row returns a an array containing all of the items in the row. Instead of printing $itest, you should print $itest[0].
You could also use mysql_fetch_assoc and print $itest['pageid'] for clarity.
mysql_fetch_row() 返回一个数组,即使它只包含一个元素。你的“回声”应该是这样的:
mysql_fetch_row() returns an array, even if it only contains one element. Your "echo" should look like this: