Hello, I have the following code, with 6 rows in the database for my query, although the mysql_fetch_row function is only able to get 5 out in my web page. I'm not sure what is wrong with my code, here it is:

$connection = mysql_connect("my server", "user", "pass") or die("Cannot connect");
mysql_select_db("db", $connection) or die("Cannot select DB");
$owner = $_GET['name'];
$sql = "SELECT * FROM imageinfo WHERE owner = '$owner'";
$result = mysql_query($sql) or die("Could not get result");
$row = mysql_fetch_row($result);
while($row = mysql_fetch_row($result))
{
	echo "$row[1], $row[2], $row[3], $row[0]";
	echo "<br />";
}

When I do the exact same query in the phpMyAdmin interface I get 6 results, although my page is only displaying 5, I have no idea why.

Recommended Answers

All 5 Replies

Just delete the line:
$row = mysql_fetch_row($result);

i guess it will solve your problem :)

Hello, I have the following code, with 6 rows in the database for my query, although the mysql_fetch_row function is only able to get 5 out in my web page. I'm not sure what is wrong with my code, here it is:

$connection = mysql_connect("my server", "user", "pass") or die("Cannot connect");
mysql_select_db("db", $connection) or die("Cannot select DB");
$owner = $_GET['name'];
$sql = "SELECT * FROM imageinfo WHERE owner = '$owner'";
$result = mysql_query($sql) or die("Could not get result");
$row = mysql_fetch_row($result);
while($row = mysql_fetch_row($result))
{
	echo "$row[1], $row[2], $row[3], $row[0]";
	echo "<br />";
}

When I do the exact same query in the phpMyAdmin interface I get 6 results, although my page is only displaying 5, I have no idea why.

Just delete the line:
$row = mysql_fetch_row($result);

i guess it will solve your problem :)

That's correct, if you delete that line it will work fine. The problem is that you were using mysql_fetch_row twice, and you were moving the internal pointer onwards, so you were always missing the first row. Keep the one inside the while loop, and delete the other!

Anthony

oops! Not sure how that ended up in there lol.

Hello..
you just delete the below line...which is before your while loop..
$row = mysql_fetch_row($result);

Then it will work fine...

oops! Not sure how that ended up in there lol.

I assume it works now yes? If you've had your problem solved, use the button on the thread page to mark it as solved, so that others who have the same problem as you will see it has been solved, and read this thread to find the solution.


Anthony

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.