inversesoft123 Posted June 21, 2010 Share Posted June 21, 2010 I have a following fields in mySQL database. 1. ups = thumb up for content (votes) 2. downs = thumb down for the content (votes) Now I want to create next and previous navigation links for required data and my query is. $subfactor = $currentfile['ups'] - $currentfile['downs']; $albumid = $currentfile['id']; $selectprevlink="SELECT * from pf_table where (((ups - downs) <= $subfactor) AND (id != $albumid)) ORDER by (ups - downs) DESC LIMIT 1"; $selectprevlink2=mysql_query($selectprevlink); $selectprevlink3=mysql_fetch_array($selectprevlink2); (id < $albumid) above is also giving wrong results. Please help me with this query here I want to get next file from database hence I have included id != (current album id). However the code bellow works perfect if value of (ups - down) is not equal to $subfactor $selectprevlink="SELECT * from pf_table where (ups - downs) < $subfactor ORDER by (ups - downs) DESC LIMIT 1"; $selectprevlink2=mysql_query($selectprevlink); $selectprevlink3=mysql_fetch_array($selectprevlink2); Thanks, very much in advance.. Quote Link to comment Share on other sites More sharing options...
dabaR Posted June 21, 2010 Share Posted June 21, 2010 What constitutes the next/previous content? Is it by date? Amount of votes? Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted June 21, 2010 Author Share Posted June 21, 2010 What constitutes the next/previous content? Is it by date? Amount of votes? Amount of vote considering.. (positive votes given to file) - (negative votes given to file) = (Fixed value to be compaired) Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted June 21, 2010 Author Share Posted June 21, 2010 Any Idea ? Now its headache Quote Link to comment Share on other sites More sharing options...
dabaR Posted June 21, 2010 Share Posted June 21, 2010 Well, what, if a post has 5 up and 3 down, then the next post is on that has 5 up and 2 down, and previous is one that has 4 up and 3 down? What if the posts have the same number of up and down votes? Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted June 21, 2010 Author Share Posted June 21, 2010 If posts has same number of ups and downs then it will rank automatically according to unique id and it works fine in index page. but when we browse content then along with back link I am trying to include quick next and previous links but getting different records from database. Like in your example (5 - 2) = 3 (5 - 3) = 2 (4 - 3) = 1 (5 - 5) = 0 5 - 5 goes last Quote Link to comment Share on other sites More sharing options...
dabaR Posted June 21, 2010 Share Posted June 21, 2010 So how about something like SELECT TOP 1 * FROM table WHERE (for - against) > $voting_score OR ((for-against) = $voting_score and id > $current_id) ORDER BY (for - against) ASC, id ASC Sorry about it being so pseudocody instead of specific. You'll have to translate to your exact code. That code is meant to have all interpolations of variables into the SQL string escaped using something like mysql_real_escape_string() as well. Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted June 22, 2010 Author Share Posted June 22, 2010 I tried this now working Quote Link to comment Share on other sites More sharing options...
dabaR Posted June 22, 2010 Share Posted June 22, 2010 Perfect, good job. 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.