This while loops does not display the first ror it gets from the mysql query. Can anyone tell me why?

$result = mysql_query("SELECT * FROM users");
if(!$result) {
	$error = true;
	$errormsg = "<p>Error running query: ".mysql_error()."</p>";
} else {
	$row = mysql_fetch_array($result);
	if(!$row) {
		$error = true;
		$errormsg = "<p>Could not get users: ".mysql_error()."</p>";
	} else {
		while($row = mysql_fetch_array($result)) {
			if($row["permissions"] == 1) {
				$user_permissions = "Normal";
			} elseif($row["permissions"] == 2) {
				$user_permissions = "Superuser";
			} else {
				$user_permissions = "Normal";
			}
			echo("
				<tr>
					<td>".$row["username"]."</td>
					<td>".$row["name"]."</td>
					<td>".$row["mail"]."</td>
					<td>".$user_permissions."</td>

			</tr>
		");				
	}
}
}

    From the manual:mysql_fetch_array
    Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.

    So the first time you call this

    $row = mysql_fetch_array($result);
        if(!$row) { 

    you are getting the first row. and the second time you call it, you are getting the second row.

      Use [man]mysql_num_rows/man instead if you just want to find out if any result rows were returned.

        Thanks guys.. 😃 You just saved me big time.. 😃

          Write a Reply...