Jump to content

Php mysql select smallest accending difference between two variables


jackr1909

Recommended Posts

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

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

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.