Note that there are some explanatory texts on larger screens.

plurals
  1. POVariable losing its value
    primarykey
    data
    text
    <p>I looked through the stack questions and answers, but didn't see anything I could directly apply here. Maybe I'm just missing something.</p> <p>The code below works fine, except when I include my where statement which refers to the value of the $wp_user_id variable.</p> <p>I've checked that the variable IS actually being populated with a $user_id when the script is loaded. It appears that the value of this variable is lost right after the call to the conManager function, but I don't understand why. There doesn't appear to be anything within the ConnectionManager.php file (which defines the conManager function) which would touch this variable, so I'm at a loss.</p> <p>I'm a PHP hack, so go easy on me, but what is causing me to lose the value of my variable, and how do I address it? Here's the code:</p> <pre><code>&lt;?php include_once("/home/evaluate/public_html/admin/php/ConnectionManager.php"); header('Content-type:text/javascript;charset=UTF-8'); $wp_user_id = $_GET["user"]; $json1=json_decode(stripslashes($_POST["_gt_json"])); $pageNo = $json1-&gt;{'pageInfo'}-&gt;{'pageNum'}; $pageSize = $json1-&gt;{'pageInfo'}-&gt;{'pageSize'}; if(isset($json1-&gt;{'sortInfo'}[0]-&gt;{'columnId'})){ $sortField = $json1-&gt;{'sortInfo'}[0]-&gt;{'columnId'}; } else{ $sortField = "miles_on_oil"; } if(isset($json1-&gt;{'sortInfo'}[0]-&gt;{'sortOrder'})){ $sortOrder = $json1-&gt;{'sortInfo'}[0]-&gt;{'sortOrder'}; } else{ $sortOrder = "ASC"; } if($json1-&gt;{'sortInfo'}[0]-&gt;{'sortOrder'} == "defaultsort"){ $sortField = "miles_on_oil"; $sortOrder = "ASC"; } if($json1-&gt;{'filterInfo'}[0]-&gt;{'value'} != "") { for ($i = 0; $i &lt; count($json1-&gt;{'filterInfo'}); $i++) { if($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "equal"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . "='" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . "' "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "notEqual"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . "!='" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . "' "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "less"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . "&lt;" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . " "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "lessEqual"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . "&lt;=" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . " "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "great"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . "&gt;" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . " "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "greatEqual"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . "&gt;=" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . " "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "like"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . " LIKE '%" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . "%' "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "startWith"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . " LIKE '" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . "%' "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == "endWith"){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . " LIKE '%" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . "' "; }elseif($json1-&gt;{'filterInfo'}[$i]-&gt;{'logic'} == ""){ $filter .= $json1-&gt;{'filterInfo'}[$i]-&gt;{'columnId'} . " LIKE '%" . $json1-&gt;{'filterInfo'}[$i]-&gt;{'value'} . "' "; } $filter .= " AND "; } } else { $filter = ''; } //print_r ($json1); //die; // Temp TEsting Values // End Temp Testing Values $conManager = new ConManager(); $conManager-&gt;getConnection(); if($json1-&gt;{'action'} == 'load'){ //to get how many records totally. $sql = "select count(*) as cnt from oil_analysis_data where $filter user_id = '".$wp_user_id."'"; $handle = mysql_query($sql); $row = mysql_fetch_object($handle); $totalRec = $row-&gt;cnt; $sql2 = "select * from oil_analysis_data where $filter user_id = '".$wp_user_id."' ORDER BY " . $sortField . " " . $sortOrder . " limit " . ($pageNo - 1)*$pageSize . ", " . $pageSize; $handle2 = mysql_query($sql2); $retArray2 = array(); while($row2 = mysql_fetch_assoc($handle2)) { // Grab Vehicle Make, Model &amp; Year "Names" from their respective tables &amp; insert into the array $year = "select Name from vehicle_data_years where ID = {$row2['list1']}"; $year1 = mysql_query($year); $year2 = mysql_fetch_assoc($year1); $year3 = $year2['Name']; $make = "select Name from vehicle_data_makes where ID = {$row2['list2']}"; $make1 = mysql_query($make); $make2 = mysql_fetch_assoc($make1); $make3 = $make2['Name']; $model = "select Name from vehicle_data_all where ID = {$row2['list3']}"; $model1 = mysql_query($model); $model2 = mysql_fetch_assoc($model1); $model3 = $model2['Name']; $row2['list1'] = $year3; $row2['list2'] = $make3; $row2['list3'] = $model3; // Grab Motor oil Viscosity, Brand &amp; Product "Names" from their respective tables &amp; insert into the array $visc = "select name from viscosity where id = {$row2['viscosity']}"; $visc1 = mysql_query($visc); $visc2 = mysql_fetch_assoc($visc1); $visc3 = $visc2['name']; $brand = "select brandname from oil_brand where brandid = {$row2['brand']}"; $brand1 = mysql_query($brand); $brand2 = mysql_fetch_assoc($brand1); $brand3 = $brand2['brandname']; $product = "select product_name from oil_data where id = {$row2['product']}"; $product1 = mysql_query($product); $product2 = mysql_fetch_assoc($product1); $product3 = $product2['product_name']; $row2['viscosity'] = $visc3; $row2['brand'] = $brand3; $row2['product'] = $product3; if($row2['bypass_filtration'] == 1) { $row2['bypass_filtration'] = "&lt;img src='http://themotoroilevaluator.com/admin/php/crud/images/checkmark.png' style='border: 0px;'&gt;"; } else {$row2['bypass_filtration'] = ""; } if($row2['oil_change'] == 1) { $row2['oil_change'] = "&lt;img src='http://themotoroilevaluator.com/admin/php/crud/images/checkmark.png' style='border: 0px;'&gt;"; } else {$row2['oil_change'] = ""; } $retArray[] = $row2; } $analysis_data = json_encode($retArray); $ret = "{data:" . $analysis_data .",\n"; $ret .= "pageInfo:{totalRowNum:" . $totalRec . "},\n"; $ret .= "recordType : 'object'}"; echo $ret; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload