I have values I’ve added to my session that I’d like to pass into an query as follows:
$eventTypeID = $this->session->userdata('eventtypeID');
$this->session->unset_userdata('eventtypeID');
$venueCityID = $this->session->userdata('venuecityID');
$this->session->unset_userdata('venuecityID');
echo json_encode($this->event_model->getSearchEvents($eventTypeID, $venueCityID));
The issue I’m running into is that last line (echo json_encode…) will not run when the prior variables are extracted/unset. If I comment out the variables, and run simply:
echo json_encode($this->event_model->getSearchEventsAll());
Then all works well. Can someone tell my why json_encode doesn’t seem to play well with sessions and how I may be able to get this to work? Thanks!
EDITED
After much frustration, it now appears the issue may not be with the session, but is instead with outputting my query:
$this->db->_compile_select();
$q = $this->db->get();
echo $this->db->last_query();
All used to work fine, and I was able to “intercept” the query to see what was being called, but now when using _compile & last_query, nothing happens????
Run
json_last_error()to see if any errors were encountered encoding the data. See the example on the docs page for proper usage:http://www.php.net/manual/en/function.json-last-error.php
We’re not certain what
$this->event_model->getSearchEvents($eventTypeID, $venueCityID)returns VS$this->event_model->getSearchEvents(), but there should definitely not be any problems related to the use of variables.As always, try
var_dump()on the output (try before decoding) and see what the differences are between the two return values of the function. You might even be encountering an error within the function itself that’s stopping execution – make sureerror_reporting()is on full-blast.