这是我在 CodeIgniter 中遇到问题的地方。我的函数 get_applicable_menu_xml() 调用 deal_sorting_counts_deal() 执行复杂查询以获取结果集。返回该集合的 num_rows() 以在生成 XML 字符串以供以后用于输出下拉选择器时使用。
由于某种原因,这失败了,似乎显示了一个永远不会停止加载的空白屏幕。
但是,如果我取消注释行 //print $this->db->last_query(); 就更奇怪了 从我返回 num_rows() 之前开始,代码就可以工作了。
而且,是的,我知道收到各种“无法修改标头信息 - 标头已经由...发送”消息以及使用的 SQL 是正常的,但是随着页面加载,数字全部返回等等。没有它,页面不会加载,并且似乎无法完成连接,就好像服务器没有响应一样。
我的问题:什么可能导致这种情况发生?我花了几天时间试图调试这个。
还要注意,这不会发生在我的本地 WAMP 服务器或用于 DEV/QA 站点的 Rackspace Linux 服务器上。它只发生在托管实时站点的 Rackspace Linux 服务器上。我环顾四周,但找不到任何可以解释其独特行为的不同特定设置。但是,我不是 Linux 服务器专家。我只是一个称职的用户。
Firebug 没有帮助,因为页面加载不够远,无法显示任何内容。
谁能提供这种奇怪行为背后的原因?谢谢,Al Pieroway
//from my database.php file (but i've played with all these)
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
//the meat of the problem these functions are in
//my models/general_model.php file
function get_applicable_menu_xml($city_sef,$btype_sef,$search_id,$days,$time,$offset,$perpage,$sort_type,$emp_lat,$emp_long,$radius=30,$merchant_list)
{
$xml = "<menu>";
$parent_cats = $this->db->query("SELECT * FROM `business_type` WHERE `btype_parent` = 0");
foreach($parent_cats->result_array() as $parent_cat)
{
$cat_count = $this->deals_sorting_counts_deal($city_sef,$parent_cat['btype_sef'],$search_id,$days,$time,$offset,$perpage,$sort_type,$emp_lat,$emp_long,$radius,$merchant_list);
$sub_cats = $this->db->query("SELECT * FROM `business_type` WHERE `btype_parent` = ".$parent_cat['btype_id']);
if($sub_cats->num_rows()>0) {
$xml .= "<category id='".$parent_cat['btype_id']."' name='".htmlentities($parent_cat['btype_name'], ENT_QUOTES)."' btype-sef='".$parent_cat['btype_sef']."' count='".$cat_count."'>";
foreach($sub_cats->result_array() as $sub_cat)
{
$sub_cat_count = $this->deals_sorting_counts_deal($city_sef,$sub_cat['btype_sef'],$search_id,$days,$time,$offset,$perpage,$sort_type,$emp_lat,$emp_long,$radius,$merchant_list);
$xml .= "<subcategory id='".$sub_cat['btype_id']."' name='".htmlentities($sub_cat['btype_name'], ENT_QUOTES)."' btype-sef='".$sub_cat['btype_sef']."' count='".$sub_cat_count."'></subcategory>";
}
$xml .= "</category>";
}
}
$xml .= "</menu>";
return '<?xml version="1.0" encoding="UTF-8"?>'.$xml;
}
function deals_sorting_counts_deal($city_sef,$btype_sef,$search_id,$days,$time,$offset,$perpage,$sort_type,$emp_lat,$emp_long,$radius=30,$merchant_list)
{
$sql11 = 'SET OPTION SQL_BIG_SELECTS = 1';
$this->db->query($sql11);/**/
$today = substr(date('l',mktime(0,0,0)),0,3);
if ($today=='Mon') { $day_to = 1; }
elseif($today=='Tue') { $day_to = 2; }
elseif($today=='Wed') { $day_to = 3; }
elseif($today=='Thu') { $day_to = 4; }
elseif($today=='Fri') { $day_to = 5; }
elseif($today=='Sat') { $day_to = 6; }
elseif($today=='Sun') { $day_to = 7; }
$string_IN ='';
if($btype_sef!='all') {
$string_IN .= $btype_sef.",";
$next_id = 0;
$this->db->select('btype_id');
$this->db->from('business_type');
$this->db->where('btype_sef',$btype_sef);
$result_id = $this->db->get();
if($result_id->num_rows()>0)
{
$row_id = $result_id->row();
$next_id = $row_id->btype_id;
$this->db->select('btype_sef');
$this->db->from('business_type');
$this->db->where('btype_parent',$next_id);
$result_str = $this->db->get();
if($result_str->num_rows()>0)
{
foreach($result_str->result_array() as $result_s)
{
$btype_sef_shild = $result_s['btype_sef'];
$string_IN .= $btype_sef_shild.",";
}
}
}
$string_IN = substr($string_IN,0,-1);
$IN_ARRAY = explode(',',$string_IN);
}
if($this->session->userdata('emp_lat')!='' and $this->session->userdata('emp_long')!='') {
$fLat = $emp_lat;
$fLon = $emp_long;
}
else {
$fLat = $emp_lat;
$fLon = $emp_long;
}
$this->session->set_userdata('emp_long',$emp_long);
$com_id = $this->session->userdata('comp_id');
$this->db->select('vendor.longitude,vendor.latitude,deals.is_time,deals.deal_img,deals.deal_avilable_custom,vendor.vendor_desc,deals.status_id as check3 ,deal_company.deal_id as deal_id,deal_company.comp_id as cmp, vendor.vendor_image,vendor.vendor_id,vendor.vendor_city_id,vendor.vendor_business_type_id,vendor.vendor_state_id,vendor.vendor_business_name,deals.start_date_time,deals.end_date_time,deals.deal_id,dtype_id,deal_name,deal_detail,deals.terms,deals.status_id,deal_sef,hero_emp_id,hero_comp_id,business_type.btype_name,deal_availabe.available_id');
$this->db->from('deals');
$this->db->join('vendor','vendor.vendor_id=deals.vendor_id');
$this->db->join('business_type','vendor.vendor_business_parent_type_id=business_type.btype_id OR vendor.vendor_business_child_type_id=business_type.btype_id OR vendor.vendor_business_parent_type_id1=business_type.btype_id OR vendor.vendor_business_child_type_id1=business_type.btype_id OR vendor.corporate_parent_category_id=business_type.btype_id OR vendor.corporate_child_category_id=business_type.btype_id' );
$this->db->join('deal_availabe','deal_availabe.deal_id=deals.deal_id');
$this->db->join('deal_company','deal_company.deal_id=deals.deal_id');
$this->db->where('deal_company.comp_id',$com_id);
$this->db->where('vendor.status_id',1);
if ($search_id!='')
{
$term = $this->db->escape_like_str(strip_tags($search_id));
$this->db->where("(deals.deal_name LIKE '%{$term}%' OR vendor.vendor_business_name LIKE '%{$term}%')");
}
if($btype_sef!='all')
{
if($string_IN=='')
{
$this->db->where('business_type.btype_sef',$btype_sef);
}
else
{
$this->db->where_in('business_type.btype_sef', $IN_ARRAY);
}
}
if($days!='all')
{
$this->session->set_userdata('day_check',$days);
$this->db->where('deal_availabe.available_id',$days);
}
else
{
$this->session->set_userdata('day_check','');
}
if($time!='all')
{
$this->db->where('deal_timeofday.tod_id',$time);
}
if($city_sef!='' && $city_sef!='all')
{
$names = array(0, $city_sef);
}
else
{
$names = array(0, 1);
}
$this->db->where('deals.status_id',1);
$date_starting = time();
$this->db->where('end_date_time >=', $date_starting);
$this->db->where('start_date_time <=', $date_starting);
$this->db->group_by('deals.deal_id');
$this->db->order_by('deals.is_feature','asc');
$this->db->limit($perpage,$offset);
$result = $this->db->get() or die("huh");
//print $this->db->last_query();
return $result->num_rows();
}