I have one mysql query
$q = mysql_query("SELECT id FROM table ORDER BY id DESC LIMIT 2");
while($row = mysql_fetch_array($q)) {...}
All I want to do is to subtract from the bigger ID the smaller one. For example I have id = 500 and id = 499 and I want 500-499 = 1 I've tried something like this
$row['id'][0]-$row['id'][1]
but it didn't work
Thank you in advance and sorry for my English
You're assuming the wrong structure for the array. $row
is an array of rows, and each row is an associative array with the columns. It should be:
$i = $row[0]['id'] - $row[1]['id'];
Next time, you can use var_dump($row)
or print_r($row)
to see what the structure looks like and figure that out for yourself.