Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple mysql query only returning one row

Tags:

sql

php

mysql

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? :/


1 Answers

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.

like image 187
William Avatar answered Jan 22 '26 17:01

William



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!