mysql - changing from 5.3 to 5.5 php getting SQL Error: 1064 in loop -


i have upgraded php 5.3 5.5 used code:

 foreach($searcharr $token)     {    foreach($longtbldef $element)             {     if (isset($element['th']) && !empty($element['th']))      $query .= "lower(" . $element['td'] . ")  '%" . strtolower($token) . "%'";    if (next($longtbldef) && !empty($element['th'])) $query .= " `or ";                 }`  if (next($searcharr)) $query .= ") , (";         } 

in 5.3 , worked fine. when use in 5.5 message: sql error: 1064 -- have error in sql syntax; check manual corresponds mysql server version right syntax use near 'lower(cases_tbl.host) '%dawn%') order cases_tbl.rec_id desc' @ line 6[]

this query:

select cases_tbl.rec_id "cases_tbl.rec_id",  cases_tbl.date_added "cases_tbl.date_added",  cases_tbl.status "cases_tbl.status",  clients_tbl.client_number "clients_tbl.client_number",  cases_tbl.matter_number "cases_tbl.matter_number",  concat(clients_tbl.client_number, '-', cases_tbl.matter_number) "concat(clients_tbl.client_number, '-', cases_tbl.matter_number)",  cases_tbl.lead_id "cases_tbl.lead_id",  lead_tbl.initials "lead_tbl.initials",  concat(lead_tbl.name_f, ' ', lead_tbl.name_l, ' (', lead_tbl.initials, ')') "concat(lead_tbl.name_f, ' ', lead_tbl.name_l, ' (', lead_tbl.initials, ')')",  cases_tbl.co_lead_id "cases_tbl.co_lead_id",  concat(co_lead_tbl.name_f, ' ', co_lead_tbl.name_l, ' (', co_lead_tbl.initials, ')') "concat(co_lead_tbl.name_f, ' ', co_lead_tbl.name_l, ' (', co_lead_tbl.initials, ')')",  cases_tbl.matter_type_id "cases_tbl.matter_type_id",  matters_tbl.matter_type "matters_tbl.matter_type",  cases_tbl.ref_name "cases_tbl.ref_name",  cases_tbl.client_id "cases_tbl.client_id",  clients_tbl.client_name "clients_tbl.client_name",  cases_tbl.client_ult "cases_tbl.client_ult",  cases_tbl.opposing_lf "cases_tbl.opposing_lf",  cases_tbl.opposing_side "cases_tbl.opposing_side",  cases_tbl.products "cases_tbl.products",  cases_tbl.description "cases_tbl.description",  cases_tbl.rate "cases_tbl.rate",  cases_tbl.servers "cases_tbl.servers",  concat(replace(servers_tbl.server_unc, '/', '/'), left(cases_tbl.ref_name, 1), '/', clients_tbl.client_number, '-', cases_tbl.matter_number, ' ', cases_tbl.ref_name) "concat(replace(servers_tbl.server_unc, '/', '/'), left(cases_tbl.ref_name, 1), '/', clients_tbl.client_number, '-', cases_tbl.matter_number, ' ', cases_tbl.ref_name)",  cases_tbl.tape "cases_tbl.tape",  cases_tbl.date_modified "cases_tbl.date_modified",  cases_tbl.host "cases_tbl.host"       cases_tbl  left join clients_tbl on cases_tbl.client_id = clients_tbl.rec_id left join matters_tbl on cases_tbl.matter_type_id = matters_tbl.rec_id left join users_tbl lead_tbl on cases_tbl.lead_id = lead_tbl.rec_id left join users_tbl co_lead_tbl on cases_tbl.co_lead_id = co_lead_tbl.rec_id left join servers_tbl on cases_tbl.servers = servers_tbl.rec_id  (  lower(cases_tbl.date_added) '%dawn%' or  lower(cases_tbl.status) '%dawn%' or  lower(concat(clients_tbl.client_number, '-', cases_tbl.matter_number)) '%dawn%' or lower(concat(lead_tbl.name_f, ' ', lead_tbl.name_l, ' (', lead_tbl.initials, ')')) '%dawn%' or  lower(concat(co_lead_tbl.name_f, ' ', co_lead_tbl.name_l, ' (', co_lead_tbl.initials, ')')) '%dawn%' or lower(matters_tbl.matter_type) '%dawn%' or  lower(cases_tbl.ref_name) '%dawn%' or  lower(clients_tbl.client_name) '%dawn%' or  lower(cases_tbl.client_ult) '%dawn%' or  lower(cases_tbl.opposing_lf) '%dawn%' or  lower(cases_tbl.opposing_side) '%dawn%' or  lower(cases_tbl.products) '%dawn%' or lower(cases_tbl.description) '%dawn%' or  lower(concat(replace(servers_tbl.server_unc, '/', '/'), left(cases_tbl.ref_name, 1), '/', clients_tbl.client_number, '-', cases_tbl.matter_number, ' ', cases_tbl.ref_name)) '%dawn%' or  lower(cases_tbl.tape) '%dawn%' or  lower(cases_tbl.date_modified) '%dawn%' or lower(cases_tbl.host) '%dawn%')   order cases_tbl.rec_id desc  

can tell me have done wrong here or if there way code loop work in 5.5? thank assistance can provide. dawn

are sure you're not coming php 5.2.3 or lower?
because looks starting php 5.2.4, behaviour of next inside foreach loops has changed.

i tested snippet @ 3v4l:

<?php $a = array('1', '2', '3', '4', '5'); foreach($a $b) {     var_dump(next($a)); } 

php 5.2.3 , earlier prints:

string(1) "2" string(1) "3" string(1) "4" string(1) "5" bool(false) 

whereas php 5.2.4-5.6.8 prints:

string(1) "3" string(1) "4" string(1) "5" bool(false) bool(false) 

instead of returning next value, returns 1 after next, evaluates false 1 iteration early.

maybe 3v4l not accurate enough php versions, if come php 5.3, try running above snippet , see gives you.

i have no idea whether intended behaviour or not, cause of problem.

if $searcharr , $longtbldef arrays have numeric keys, use $key => $value form in foreach , check if next element exists isset($longtbldef[$key + 1]), universal solution build array instead of string , using implode on after loop:

$and = []; foreach($searcharr $token) {     $or = [];     foreach($longtbldef $element)     {         if(isset($element['th']) && !empty($element['th']))         {             $or[] = "lower(".$element['td'].") '%".strtolower($token)."%'";         }     }     $and[] = implode(' or ', $or); } $query .= implode(') , (', $and); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -