Hello.
My name is Victor Rivarola. I am currently working on a system that is currently eating the first row. Yes, I have made sure that I am not fetching the rows at an incorrect time.
But first, I know that the mysql_* functions have been depreciated and should not be added to new code. Well, this is not new code but existing code I am maintaining.
This is my code:
<?php
include_once("config.php");
ob_start('mb_output_handler');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
header("Content-type: text/html; charset=utf-8");
// These combined checks both verify the validity of the input
// and prevent against SQL injection
$city = @$_GET['city'] or die("Required parameter(s) is missing.");
is_numeric($city) ? true : die("Improper city code received.");
$sql = "
SELECT schools_ID
,name
FROM InfResp_schools
WHERE cities_ID=$city
ORDER BY name ASC
";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo "<options value=\"".$row["schools_ID"]."\">".$row["name"]."<option>\n";
}
mysql_free_result($result);
DB_disconnect();
?>
The InfResp_schools table has 3 fields in it,
schools_ID which is the primary key,
cities_ID which is a foreign key to a different cities table, and the
name field whose contents should be obvious.
This is fed using AJAX and jquery right into a select box. This part is working perfectly.
I have searched for this problem's solution for a long time. While I have found similar problems, it is always caused by people inserting a superfluous
mysql_fetch_assoc(). As you can see, I am not doing that.
I have checked the above SQL command for various city codes in my database. The result is perfect. So I know that my SQL is fine. It must be a problem in my PHP.
Anyway, the result is always the same. The first school gets omitted for all cities in my database. Does anyone has an idea why?