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();

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.