当数组来自 mysql_fetch_array 时显示 php 中的数组差异
displaying array difference in php when arrays coming from mysql_fetch_array
我正在设计一个 php 脚本,它显示特定旅行社在给定日期的可用巴士。这是 php 代码片段。
$query1 = mysql_query("SELECT bus_id FROM schedule WHERE travel_agency_id = '".$travel_agency_id."' AND scheduleddate ='".$busDate."'");
$query2 = mysql_query("SELECT bus_id FROM pc WHERE travel_agency_id = '".$travel_agency_id."' ");
$array1 = array(@mysql_fetch_array($query1));
$array2 = array(@mysql_fetch_array($query2));
$diff = array_diff($array2, $array1);
print_r ($diff);
我认为上面的查询会在给定日期"$busDate"
打印旅行社ID "$travel_agency_id"
的"bus_id"
s。但是出现如下错误。
Notice: Array to string conversion in.......... Array ( [0] => )
谁能解释为什么会发生这个错误..?如何使用 "echo"
显示可用总线数组 (id)?
试试这个..
$query1 = mysql_query("SELECT bus_id FROM schedule WHERE travel_agency_id = '".$travel_agency_id."' AND scheduleddate ='".$busDate."'");
$query2 = mysql_query("SELECT bus_id FROM pc WHERE travel_agency_id = '".$travel_agency_id."' ");
if(mysql_num_rows($query1) > 0 && mysql_num_rows($query2) > 0 ){
$array1 = mysql_fetch_array($query1);
$array2 = mysql_fetch_array($query2);
$diff = array_diff($array2, $array1);
print_r ($diff);
}
我正在设计一个 php 脚本,它显示特定旅行社在给定日期的可用巴士。这是 php 代码片段。
$query1 = mysql_query("SELECT bus_id FROM schedule WHERE travel_agency_id = '".$travel_agency_id."' AND scheduleddate ='".$busDate."'");
$query2 = mysql_query("SELECT bus_id FROM pc WHERE travel_agency_id = '".$travel_agency_id."' ");
$array1 = array(@mysql_fetch_array($query1));
$array2 = array(@mysql_fetch_array($query2));
$diff = array_diff($array2, $array1);
print_r ($diff);
我认为上面的查询会在给定日期"$busDate"
打印旅行社ID "$travel_agency_id"
的"bus_id"
s。但是出现如下错误。
Notice: Array to string conversion in.......... Array ( [0] => )
谁能解释为什么会发生这个错误..?如何使用 "echo"
显示可用总线数组 (id)?
试试这个..
$query1 = mysql_query("SELECT bus_id FROM schedule WHERE travel_agency_id = '".$travel_agency_id."' AND scheduleddate ='".$busDate."'");
$query2 = mysql_query("SELECT bus_id FROM pc WHERE travel_agency_id = '".$travel_agency_id."' ");
if(mysql_num_rows($query1) > 0 && mysql_num_rows($query2) > 0 ){
$array1 = mysql_fetch_array($query1);
$array2 = mysql_fetch_array($query2);
$diff = array_diff($array2, $array1);
print_r ($diff);
}