PHP loop is ignoring the first MySQL row

For some reason, my PHP loop is skipping the first row of my MySQL query.

I run this:

$query = "SELECT * FROM data";
			  
$result = mysql_query($query); 
$row = mysql_fetch_assoc($result);
$num = mysql_num_rows($result);

echo "<ol>";
while($row = mysql_fetch_assoc($result)){
   echo "<li>".$row['row_name']."</li>";
}
echo "</ol>";
echo $num;

And it outputs this (it prints 20 rows, but the row count at the end says 21, which is correct). There is a row before “1. Breast Augmentation” that is not showing.

  1. Breast Augmentation (000s)
  1. Hair Transplantation (000s)
  2. Rhinoplasty (000s)
  3. Blepharoplasty (000s)
  4. Abdominoplasty (000s)
  5. Breast Reduction (Women) (000s)
  6. Breast Lift (000s)
  7. Gynecomastia Treatment (000s)
  8. Lip Augmentation (000s)
  9. Facelift (000s)
  10. Otoplasty (000s)
  11. Buttock Augmentation (000s)
  12. Upper Arm Lift (000s)
  13. Forehead Lift (000s)
  14. Chin Augmentation (000s)
  15. Buttock Lift (000s)
  16. Thigh Lift (000s)
  17. Vaginal Rejuvenation (000s)
  18. Lower Body Lift (000s)
  19. Cheek Implants (000s)

21

Here is what my table is:

-- phpMyAdmin SQL Dump
-- version 3.1.3.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 24, 2011 at 10:26 AM
-- Server version: 5.1.33
-- PHP Version: 5.2.9

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `lsicast`
--

-- --------------------------------------------------------

--
-- Table structure for table `data`
--

DROP TABLE IF EXISTS `data`;
CREATE TABLE IF NOT EXISTS `data` (
  `data_id` int(11) NOT NULL AUTO_INCREMENT,
  `table_id` int(11) NOT NULL,
  `row_name` varchar(255) NOT NULL,
  `2007` varchar(255) NOT NULL,
  `2008` varchar(255) NOT NULL,
  `2009` varchar(255) NOT NULL,
  `2010` varchar(255) NOT NULL,
  `2011` varchar(255) NOT NULL,
  `2012` varchar(255) NOT NULL,
  `2013` varchar(255) NOT NULL,
  `2014` varchar(255) NOT NULL,
  `cagr` varchar(255) NOT NULL,
  PRIMARY KEY (`data_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;

--
-- Dumping data for table `data`
--

INSERT INTO `data` (`data_id`, `table_id`, `row_name`, `2007`, `2008`, `2009`, `2010`, `2011`, `2012`, `2013`, `2014`, `cagr`) VALUES
(1, 1, 'Liposuction (000s)', '42', '71', '117', '192', '313', '507', '817', '1,312', '62.1%'),
(2, 1, 'Breast Augmentation (000s)', '37', '64', '110', '186', '316', '530', '886', '1,475', '68.2%'),
(3, 1, 'Hair Transplantation (000s)', '53', '63', '73', '84', '95', '106', '117', '126', '11.6%'),
(4, 1, 'Rhinoplasty (000s)', '20', '35', '60', '100', '161', '251', '377', '543', '55.2%'),
(5, 1, 'Blepharoplasty (000s)', '19', '34', '58', '99', '170', '285', '476', '785', '68.4%'),
(6, 1, 'Abdominoplasty (000s)', '19', '32', '55', '91', '147', '240', '384', '608', '61.9%'),
(7, 1, 'Breast Reduction (Women) (000s)', '10', '18', '32', '57', '99', '169', '286', '471', '70.9%'),
(8, 1, 'Breast Lift (000s)', '11', '19', '32', '52', '83', '130', '204', '311', '57.7%'),
(9, 1, 'Gynecomastia Treatment (000s)', '10', '16', '25', '38', '57', '85', '125', '181', '48.9%'),
(10, 1, 'Lip Augmentation (000s)', '8', '14', '23', '36', '56', '86', '130', '196', '54.1%'),
(11, 1, 'Facelift (000s)', '7', '12', '20', '34', '55', '86', '131', '196', '57.2%'),
(12, 1, 'Otoplasty (000s)', '6', '10', '16', '26', '42', '67', '102', '153', '57.3%'),
(13, 1, 'Buttock Augmentation (000s)', '7', '10', '15', '21', '30', '41', '55', '71', '36.8%'),
(14, 1, 'Upper Arm Lift (000s)', '6', '8', '11', '15', '19', '23', '28', '33', '23.7%'),
(15, 1, 'Forehead Lift (000s)', '2', '5', '9', '17', '31', '57', '101', '174', '81.5%'),
(16, 1, 'Chin Augmentation (000s)', '4', '6', '8', '11', '16', '21', '28', '35', '34.5%'),
(17, 1, 'Buttock Lift (000s)', '4', '6', '7', '8', '10', '11', '13', '14', '15.9%'),
(18, 1, 'Thigh Lift (000s)', '2', '3', '4', '7', '10', '15', '21', '29', '46.6%'),
(19, 1, 'Vaginal Rejuvenation (000s)', '2', '2', '4', '5', '7', '10', '12', '16', '34.4%'),
(20, 1, 'Lower Body Lift (000s)', '1', '2', '3', '5', '8', '11', '16', '23', '46.6%'),
(21, 1, 'Cheek Implants (000s)', '1', '1', '2', '2', '3', '3', '4', '5', '24.3%');

Here is what my table looks like

Now if I run this query “SELECT * FROM data” in MySQL phpMyAdmin, it shows 21 rows as it should. Why isn’t my first row printing?


$query = "SELECT * FROM data";
              
$result = mysql_query($query); 
// $row = mysql_fetch_assoc($result);
$num = mysql_num_rows($result);

echo "<ol>";
while($row = mysql_fetch_assoc($result)){
   echo "<li>".$row['row_name']."</li>";
}
echo "</ol>";
echo $num; 

Your while statement starts at the second row because you are fetching the first row just above.


$row = mysql_fetch_assoc($result);

thanks guys