Jump to content

[SOLVED] Query always returning first row of db.


hellonoko

Recommended Posts

My code below always seems to return just the first row of the DB when it should return different rows.

 

The code always returns: 8

8 is the value of the first id row in the DB.

 

Above this code I am also echoing the  $id_rank value so it should be getting proper input.

 

Any ideas?

 

Thanks for your time,

ian

 

$query = "SELECT id FROM ideas WHERE rank < '$id_rank' LIMIT 1";
	$result = mysql_query($query) or die (mysql_error());
	$row = mysql_fetch_assoc($result) or die (mysql_error());

	$moving_idea_id = $row['id'];

	// moves item rank DOWN one.
	echo $moving_idea_id;
	exit();

Well.

 

I thought I had solved it by taking the value from query string but I actually need to get the row previous to that row.

 

But then I did solve it. (Seems to be working) Code below.

 

// get ID of idea below one to be moved.
	$query = "SELECT id FROM ideas WHERE rank < $id_rank ORDER BY ID DESC LIMIT 1";
	$result = mysql_query($query) or die (mysql_error());
	$row = mysql_fetch_assoc($result) or die (mysql_error());

	$moving_idea_id = $row['id'];

	// moves item rank DOWN one.
	echo $moving_idea_id;
	exit();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.