Jump to content

Missing first record in sql query


Guest coolcat
 Share

Recommended Posts

Guest coolcat

Hi i am trying to do a php query but apparantly when i retrieve the records, there is always one thats not displayed. Was wondering if anyone can help me with this problem. Below is the code i've written. Thanks.<?phpfunction LoadRegionList($Country){$mysql = mysql_connect("localhost", "root", "bukopie");//if (mysql_connect_errno()) {// printf("Connect failed: %s\n", mysql_connect_error());// exit();//} else { $db_selected=mysql_select_db("mydb", $mysql); $sql = "SELECT * FROM Region where country_num='" .$Country. "'"; $res = mysql_query($sql,$mysql); if ($res) { while ($newArray = mysql_fetch_array($res, MYSQL_ASSOC)) //for($i = 1; $i < 5; $i++) { echo('<option value="'.$newArray['region_num'].'">'.$newArray['region_name'].'</option>'); //echo('<option value="'.$i.'">'.$i.'</option>'); } echo('</select>'); } else { printf("Could not retrieve records: %s\n", mysql_error($mysql)); }// mysql_free_result($res); mysql_close($mysql);//}}?>

Link to comment
Share on other sites

Everything looks fine to me, run the query in something like phpMyAdmin to check the result set, but there's nothing in the code that would skip the first or last result. The only thing I see is that you print a </select> without printing a <select>, but that might get printed somewhere else.

<?phpfunction LoadRegionList($Country){  $mysql = mysql_connect("localhost", "root", "bukopie");  $db_selected=mysql_select_db("mydb", $mysql);  $sql = "SELECT * FROM Region where country_num='" .$Country. "'";  $res = mysql_query($sql,$mysql);  if ($res)  {	while ($newArray = mysql_fetch_array($res, MYSQL_ASSOC))	{	  echo('<option value="'.$newArray['region_num'].'">'.$newArray['region_name'].'</option>');	}	echo('</select>');  }  else   {	printf("Could not retrieve records: %s\n", mysql_error($mysql));  }  mysql_close($mysql);}?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...