php - Displaying just three consecutive values from database -


imagine database table named geography contains information world's countries, including each country's area in miles , kilometers. want write articles each country, using database list statistics, including size (area) - twist.

an article vietnam, example, list areas vietnam , next biggest , next smallest countries, ranked biggest (top) smallest, this:

malaysia | 329,750

vietnam | 329,560

norway | 324,220

i can create table displays value countries. can show me how display 3 consecutive values, featured country in center?

a couple notes: first, values in database not have commas (e.g. 18070). also, include decimals (e.g. 0.2). however, if problem alter data, adding commas , rounding numbers off.


the answer below makes sense me, don't understand how implement it; i'm getting syntax error.

i'm using actual values, i'm using different table - gw_geog_states_geog - contains values u.s. states. i'm trying access 2 values - idarea (which lists id's states; example, us-vt = vermont) , area (the size in square miles).

i suspect problem caused line:

$stm->execute(array(  'myurl'=>$myurl )); 

here's entire script:

$myurl = 'us-vt';  $stm = $pdo->prepare("select t.* ((select idarea, area    gw_geog_states_geog    idarea = 'us-vt'   ) union   (select idarea, area    gw_geog_states_geog    area > (select area gw_geog_states_geog idarea =   'us-vt')    order area    limit 1   ) union   (select idarea, area    gw_geog_states_geog    area < (select area gw_geog_states_geog idarea = 'us-vt')    order area desc    limit 1   )  ) t order size;") 

my latest revision works if add parentheses @ beginning , delete following:

$stm->execute(array( 'myurl'=>$myurl )); 

you can using union all , limit:

(select c.*  countries   country = 'vietnam' ) union (select c.*  countries  size > (select size countries country = 'vietnam')  order size  limit 1 ) union (select c.*  countries  size < (select size countries country = 'vietnam')  order size desc  limit 1 ) order size 

this works fine long there no ties -- , don't think there 2 countries same area.

edit:

try this:

$stm = $pdo->prepare" select t.* ((select idarea, area        gw_geog_states_geog        idarea = 'us-vt'       ) union       (select idarea, area        gw_geog_states_geog        area > (select area gw_geog_states_geog idarea = 'us-vt')        order area        limit 1       ) union       (select idarea, area        gw_geog_states_geog        area < (select area gw_geog_states_geog idarea = 'us-vt')        order area desc        limit 1       )      ) t order size;") 

and continue rest of php code.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -