Reputation:
I have the following table:
CREATE TABLE IF NOT EXISTS `notes` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`note` text,
PRIMARY KEY (`id`)
)
INSERT INTO `notes` (`id`, `uid`, `note`) VALUES
(1, 1, 'noteteeext'),
(2, 1, 'notenotenotenote');
As you can see i have 2 rows with uid=1 but it only returns 1 row! (the second one)
$sql = "SELECT id,uid,note
FROM notes
WHERE uid = 1";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo $row['note'];
}
What's wrong? :/
Upvotes: 2
Views: 5715
Reputation: 200
Have you checked and analyzed the source of the PHP output? Maybe the first row gets lost in HTML somewhere.
As the answer below also states, this is not the case if the posted code is exactly the code you are running, but if there is some HTML code as well in there, then this might happen.
Upvotes: 0
Reputation: 13632
Are you sure there definitely isn't a $row = mysql_fetch_assoc($result)
prior to the while loop in the actualy code you are running?
Obviously this is not the problem if the code you have posted above is exactly what you are running, but this would be the most common cause of this behaviour.
Upvotes: 6
Reputation: 40675
Are you sure you haven't just miss-looked because it's all written to one line since you're not adding any line break?
Plus. Since the type of uid is INT, you should write
WHERE uid = 1
instead of
WHERE uid = '1'
Upvotes: 3
Reputation: 12667
Not seeing anything obvious, so I'll go with the simple stuff:
Have you:
Long shots these, but maybe something will help.
Upvotes: 6