hellonoko Posted December 18, 2007 Share Posted December 18, 2007 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(); Quote Link to comment Share on other sites More sharing options...
bobahad Posted December 18, 2007 Share Posted December 18, 2007 Not too experience with these things but doesn't Limit 1 mean return just 1 Quote Link to comment Share on other sites More sharing options...
hellonoko Posted December 18, 2007 Author Share Posted December 18, 2007 Yes it does. That is what I want to do. But it doesn't mean return the first one just 1. Could be middle one. Last one. In this case it is one below the current one. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted December 18, 2007 Share Posted December 18, 2007 Is `rank` an INTEGER column? If so, try removing the single quotes around $id_rank in your query. Quote Link to comment Share on other sites More sharing options...
hellonoko Posted December 18, 2007 Author Share Posted December 18, 2007 Tried that and yes it is. Actually just realized that the value I need 'id' is passed over earlier in the query string. Stupid me. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 18, 2007 Share Posted December 18, 2007 So is it solved? Quote Link to comment Share on other sites More sharing options...
hellonoko Posted December 18, 2007 Author Share Posted December 18, 2007 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(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.