I have a MySQL table with reports. Fetching my reports is used by function:
我有一个带有报告的MySQL表。取回我的报告的功能是:
function fillItByRoute($lat){
global $db;
$array = array(array());
$result = $db->query("SELECT * FROM reports WHERE latitude LIKE '$lat%' ORDER BY datetime_view");
while ($row = $db->fetch_array($result)){
$array[$int][1] = "Desc";
$array[$int][2] = $row['latitude'];
}
return $array;
}
}
which creates an multidimensional array.
它创建了一个多维数组。
- [latitudes in MySQL are stored like 25.33236645, 23.2665666 etc...]
- [MySQL的纬度存储为25.33236645,23.2665666等]
I have a different array:
我有一个不同的数组:
$array_lat = array(25.5,23.1,45.2);
So, I would like to know if it is possible to get through array values of $array_lat with checking the match with values from multidimensional array created by function fillItByRoute() and storing values of function fillItByRoute() in new array?
因此,我想知道是否可以通过使用函数fillItByRoute()创建的多维数组中的值和在新数组中存储函数fillItByRoute()的值,来获得$array_lat的数组值。
One more time, shortly:
一次,不久:
- There are different values in $array_lat;
- 在$array_lat中有不同的值;
- I want to check function fillItByRoute() with input of $array_lat
- 我要检查函数fillItByRoute(),输入$array_lat。
- Results, which suit have to be stored in new array.
- 结果,suit必须存储在新数组中。
- The new array should be with values (using values of my $array_lat): 25.5666332, 25.511433, 23.1233, 23.11444, 23.1, 45.269...etc, could be even hundreds of items.
- 新数组应该具有值(使用$array_lat的值):25.5666332、25.511433、23.1233、23.11444、23.1、45.269……等等,甚至可能是上百个项目。
Is it possible to do something like that?
有可能做这样的事吗?
Thank you very much!
非常感谢!
2 个解决方案
#1
0
I think you want something like this. It iterates through your array_lat and compares it to a value from SQL. I'm not entirely sure what you want to do with the comparison but you should put it in the if statement from the second function. If you want a new array it looks like you understand how to create those but let me know if this is too ambiguous.
我想你想要这样的东西。它遍历您的array_lat,并将其与SQL的值进行比较。我不完全确定你想做什么比较,但你应该把它放在if语句中,从第二个函数。如果你想要一个新的数组,它看起来就像你知道如何创建它们,但是如果这太模糊,请告诉我。
function fillItByRoute($lat){
global $db;
$array = array(array());
$result = $db->query("SELECT * FROM reports WHERE latitude LIKE '$lat%' ORDER BY datetime_view");
while ($row = $db->fetch_array($result)){
$array[$int][1] = "Desc";
$array[$int][2] = $row['latitude'];
}
return $array;
function compareArrToSql($array_lat){
for($curr_lat = 0; $curr_lat<count($array_lat); $curr_lat++){
$sql_val = fillItByRoute($array_lat[$curr_lat]);
if($array_lat[$curr_lat]==$sql_val){
}
}
}
#2
0
If my assumption about what you meant is correct, this is what you are after:
如果我假设你的意思是正确的,这就是你所追求的:
function fillItByRoute($lat){
global $db;
$array = array(array());
$result = $db->query("SELECT * FROM reports WHERE latitude LIKE '$lat%' ORDER BY datetime_view");
while ($row = $db->fetch_array($result)){
$latitude = number_format((float)$row['latitude'], 2, '.', '');
if (in_array($latitude,$lat)) {
$array[$int][1] = "Desc";
$array[$int][2] = $row['latitude'];
}
}
return $array;
}
#1
0
I think you want something like this. It iterates through your array_lat and compares it to a value from SQL. I'm not entirely sure what you want to do with the comparison but you should put it in the if statement from the second function. If you want a new array it looks like you understand how to create those but let me know if this is too ambiguous.
我想你想要这样的东西。它遍历您的array_lat,并将其与SQL的值进行比较。我不完全确定你想做什么比较,但你应该把它放在if语句中,从第二个函数。如果你想要一个新的数组,它看起来就像你知道如何创建它们,但是如果这太模糊,请告诉我。
function fillItByRoute($lat){
global $db;
$array = array(array());
$result = $db->query("SELECT * FROM reports WHERE latitude LIKE '$lat%' ORDER BY datetime_view");
while ($row = $db->fetch_array($result)){
$array[$int][1] = "Desc";
$array[$int][2] = $row['latitude'];
}
return $array;
function compareArrToSql($array_lat){
for($curr_lat = 0; $curr_lat<count($array_lat); $curr_lat++){
$sql_val = fillItByRoute($array_lat[$curr_lat]);
if($array_lat[$curr_lat]==$sql_val){
}
}
}
#2
0
If my assumption about what you meant is correct, this is what you are after:
如果我假设你的意思是正确的,这就是你所追求的:
function fillItByRoute($lat){
global $db;
$array = array(array());
$result = $db->query("SELECT * FROM reports WHERE latitude LIKE '$lat%' ORDER BY datetime_view");
while ($row = $db->fetch_array($result)){
$latitude = number_format((float)$row['latitude'], 2, '.', '');
if (in_array($latitude,$lat)) {
$array[$int][1] = "Desc";
$array[$int][2] = $row['latitude'];
}
}
return $array;
}