English 中文(简体)
Php Read Query - Selected 2 Values - Ron Some Maths On specific Row Value Add Value To New Column?
原标题:Php Read SQL Query - Select 2 Values - Run Some Maths On Specific Row Value Add Value To New Column?

问题: 我请我问一下。 我希望能够把这个数字拉到一个阵列中(现在我就是这样),但随后从各行中取出一个具体价值,得出一些数学(我有这句话),然后把这一数学的结果加到同一阵列或新阵列中最后(或一开始)能够提供的价值。

这样做是为了确定目前构成SQ查询的一部分的地点,然后确定每次活动(每行一次)的距离。

页: 1 Query -> 检查活动地点-> 在现有地点运行远距离数学,以进行活动-> 改装成像(SQL Query + Distance)一样,准备用于 j子。

我将补充说,我已设法这样做,以便用Xml的方式去做,但是,在操纵阵列方面,Im仍是一个灯塔。

成就

Terran

    // Connect to database server   
$con = mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword) or die(mysql_error());
mysql_select_db($config_databaseName, $con);    

// Access tables    
$sql = "SELECT * FROM " . $config . " WHERE LAT <" . $toplat . " AND LAT > " . $bottomlat . " AND LONG > " . $leftlon . " AND LONG < " . $rightlon . " AND VALIDPERIOD_STARTOFPERIOD <  " . $nowtime . "  AND VALIDPERIOD_ENDOFPERIOD >  " . $nowtime ." )";

// Execute query
$result = mysql_query($sql) or die(mysql_error());

$lata = $latitude;
$lona = $longitude;
    // Need to populate these from each row values in the query
$latb = $sqllat;
$lonb = $sqllong;                   
// need to place this in to a colum at the end of each row
    $distancefromevent = coordDistance($lata, $longa, $latb, $lonb, "m");

    // need to reform all the above so I can carry on and use the code that follows


$responses = array();
if(mysql_num_rows($result)) {
  while($response = mysql_fetch_assoc($result)) {
    $responses[] = array( dataitem =>array_map( utf8_encode ,$response));
  }
}

header( Content-type: application/json );
$json = json_encode(array($config_datexdeftype=>$responses));

$callback = $_GET[callback];
echo $callback .  (  . $json .  ) ;

};

return TRUE;
问题回答

• 要求你计算一个地点(纬度)与空洞之间的距离?

If yes this is the way: https://developers.google.com/maps/articles/phpsqlsearch?hl=hu-HU

This should work.

请注意,可读性用[...]取代了一些较长的代码。

// Connect to database server   
$con = mysql_connect([...]) or die(mysql_error());
mysql_select_db($config_databaseName, $con);    

// Access tables    
$sql = "SELECT * FROM " . $config . " WHERE [...]";

// Execute query
$result = mysql_query($sql) or die(mysql_error());

// Prepare the loop
$lata = $latitude;
$lona = $longitude;
$responses = array();

// Loop over each records (stay correct even if there is no record)
while($response = mysql_fetch_assoc($result)) {
    // we assume that latitude and longitude are given by
    //  columns  lat  and  lon  in the SQL query.
    $latb = $response[ lat ]; 
    $lonb = $response[ lon ];
    $distancefromevent = coordDistance($lata, $longa, $latb, $lonb, "m");
    $response[ distance ] = $distancefromevent;
    $responses[] = array( dataitem =>array_map( utf8_encode ,$response));
}

header( Content-type: application/json );
$json = json_encode(array($config_datexdeftype=>$responses));

$callback = $_GET[callback];
echo $callback .  (  . $json .  ) ;

return TRUE;




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签