Hi, I'm having trouble running a query and displaying the results. Basically, I'm able to enter in data into the database correctly. But when I try to pull up the results, only some of the entries will show up as opposed to all of them.
Here is my MySQL table:
CREATE TABLE students (
student_id TINYINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
first_name VARCHAR(200) NOT NULL,
last_name VARCHAR(200) NOT NULL,
score VARCHAR(3) NOT NULL,
month VARCHAR(30) NOT NULL,
year VARCHAR(4) NOT NULL,
PRIMARY KEY (student_id)
)
And here is the PHP code I'm using:
$query = "SELECT * FROM students ORDER BY last_name ASC";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
while ($row = mysql_fetch_array($result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$score = $row['score'];
$month = $row['month'];
$year = $row['year'];
echo "<tr><td>$first_name</td><td>$last_name</td><td>$score</td><td>$month $year</td></tr>";
}
Again, that doesn't display all of the records. What am I doing wrong? I've also tried alternative versions of the query, since my goal is to separate the results alphabetically into different pages. So, I've tried:
$query = "SELECT * FROM students WHERE last_name between 'A%' and 'F%' ORDER BY last_name ASC";
and
$query = "SELECT * FROM students WHERE last_name like 'A%' or last_name like 'B%' ORDER BY last_name ASC";
Same result, only some of the records show up. I've been trying to figure this out for a while. Any help would be appreciated. Thank you.