jackr1909 Posted January 3, 2012 Share Posted January 3, 2012 Hi everyone, I have this php code, which connects to a mysql database (through dbconnect.php) and is meant to select the lowest difference between two variables. I can't get very far. The most valuable differences are not the lowest per se, as much as the closest to 0, either positive or negative. Both numbers are positive integers. The page dictates the relative 'ranking' of the page, by multiplying the rank by 20, so that with each successive page, the retrospective line is 20 higher in ranking. The section 20*$page+x is not a value, but a ranking, so the instance would by, in words 'select the lowest difference between two numbers. If the number closest to 0 cannot be selected, can we find the highest value out of the two variables and subtract the lower (they are interchangeable) <?php $page = $_GET['page']; include("dbc.php") //connect to mysql database $result = mysql_query("SELECT * FROM posts {WHERE (ROW1-ROW2) = 20*$page +1}"); // { indicates my unsure section while($row = mysql_fetch_array($result)){ $id = $row['id']; $username = $row['id']; $sum1 = $row['id']; $sum2 = $row['id']; } $result1 = mysql_query("SELECT * FROM posts {WHERE (ROW1-ROW2) = 20*$page +2}"); // { indicates my unsure section while($row1 = mysql_fetch_array($result1)){ $id2 = $row['id']; $username2 = $row['id']; $2sum1 = $row['id']; $2sum2 = $row['id']; } //this continues with the mysql $page+x increasing successively ?> Also, could we apply a formula that would increase the weighting of those with a higher sum. Thanks a lot, this is really over my head Jack Link to comment https://forums.phpfreaks.com/topic/254238-php-mysql-select-smallest-accending-difference-between-two-variables/ Share on other sites More sharing options...
PaulRyan Posted January 3, 2012 Share Posted January 3, 2012 I think I may know what you want, but not 100% Tell me the expected output you want, as well as explain a little more clearly your problem? Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/254238-php-mysql-select-smallest-accending-difference-between-two-variables/#findComment-1303515 Share on other sites More sharing options...
jackr1909 Posted January 3, 2012 Author Share Posted January 3, 2012 It would be the lowest sum of two mysql variables accending upwards, multiplied by the page. Sorry about the complicatedness of the question. The actual output would just be echoing those local variables i set in a div Thanks Link to comment https://forums.phpfreaks.com/topic/254238-php-mysql-select-smallest-accending-difference-between-two-variables/#findComment-1303519 Share on other sites More sharing options...
jackr1909 Posted January 3, 2012 Author Share Posted January 3, 2012 Found a better approach to the problem, (just for curiosity, the values will be added pre-serverside then divided by another variable) thanks for your help anyway, Jack Renshaw Link to comment https://forums.phpfreaks.com/topic/254238-php-mysql-select-smallest-accending-difference-between-two-variables/#findComment-1303614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.