I fetching data from DB and passing to Google Map. But sometimes in address table, lat and lng rows are being empty. So if it happens and I use that half empty array Google Map is crushes. So when I fetching data in Controller is there any option like; if row empty go next row... For example:
public function index()
{
$Data = DB::table('allestates')->whereNotNull('lat')->whereNotNull('lng')->get();
return view('home', 'Data');
}
Of course this is not proper code but, I just want to show what I am trying. Is this possible?
You can use whereNotNull:
public function index()
{
$Data = DB::table('allestates')->whereNotNull('lat')->whereNotNull('lng')->get();
if (!empty($Data)){
}
}
The filter you used (where('lat','lng')) actually means "records where the field lat has the value 'lng'".
you can add check if a field is not null by using below code:
$Data = DB::table('allestates')
->whereNotNull('lat')
->whereNotNull('lng')
->get();
if (!empty($Data)){
}
Related
I need display the value in the ga845_clients table in the atacado column, that have 's' or 'n' recorded, but they return blank.
Then when I call <?php echo $this->session->userdata('usu_id');?> in view, the ID is displayed.
I have checked that usu_id is the session ID and the same value from id of table ga845_clientes.
I created the following codes:
Model (Cliente_model.php):
public function getAtacadista($id) {
$this->db->select("atacadista");
$this->db->where('id', $this->session->userdata("usu_id"));
$query = $this->db->get('ga845_clientes');
return $query->result();
}
Controller (Cliente.php):
public function getAtacadista() {
$this->load->model('cliente_model');
$this->load->view("carrinho", $data);
$data['atacadista'] = $this->cliente_model->getAtacadista($id);
}
View (carrinho.php)
echo 'test1:' .$data['atacadista'];
echo 'test2:' .$atacadista;
Remember, $data['atacadista'] dont exists on view, only $atacadista
Also move down the " load view " line, as everton suggested, they are swapped and $data need to be before.
And lastly, as a tip, session userdata can contain a bunch of info, and you should pass the name of the session, not of the value, maybe usu_id is a value inside an array, not the array itself.
You can try the following in your controller
public function getAtacadista() {
$this->load->model('cliente_model');
$data['atacadista'] = $this->cliente_model->getAtacadista($id);
$this->load->view("carrinho", array("data"=>$data));
}
You should place the $data variable assign before the load view.
Because you are not sending your data to the view. change the sequence of your statements.
public function getAtacadista() {
$this->load->model('cliente_model');
$data['atacadista'] = $this->cliente_model->getAtacadista($id);
$this->load->view("carrinho", $data);
}
I am trying to iterate over the arrays from the database doctrine query. On getting the value of the id field, set it as the return type value of the method. On getting the endpoint uri it returns status 200 - the response is empty
This is my attempt.
/**
* #Route("/get/{email}")
*/
public function emailAction($email)
{
$var = "";
$singleresult = $this->getDoctrine()->getRepository('Api3Bundle:Influ')->findOneBy(array('email' => $email));
if ($singleresult === null) {
return new View("user not found", Response::HTTP_NOT_FOUND);
}
//area of problem
foreach($singleresult as $users)
{
$var = $users.id;
}
return $var;
//end of area of problem
}
I am trying to use email to return the id. The above attempt show through postman that the response is empty
If $singleresult has just one result, then why are you using foreach() on it?
If $singleresult has more than one result, you are going to loop through them all and return the last one (because all previous $var's will be overwritten.
Can't you access it directly $singleresult->id without the loop?
If the id is empty, perhaps you could start doing some debugging by returning everything inside of $singleresult to see why there is no id.
I have user information stored in a separate database from my Wordpress installation. I'm writing a plugin that queries this database and pre-fills values in a specific gravity form.
It looks like the following filter does what I need:
add_filter("gform_field_value_$PARAMETER", "FUNCTION");
The problem with this is that I need to call a function for each parameter value. That means that I query the database for each value.
So if I have eight pre-filled values, the database gets queried eight times. That seems inefficient.
Is there a way that I can query the database once, get all the values I need, then pass back the variables to the filters?
Here is my preferred way to handle this. Wrap your code in a class and store your query results in a variable in that class. You can then check if that variable already contains data and if so, simply return that already retrieved data rather than querying the database again.
class My_GF_Field_Values {
var $data = null;
function __construct() {
add_filter( 'gform_field_value_param1', array( $this, 'func1' ) );
add_filter( 'gform_field_value_param2', array( $this, 'func2' ) );
}
function func1() {
$data = $this->get_data();
return $data['param1'];
}
function func2() {
$data = $this->get_data();
return $data['param2'];
}
function get_data() {
if( $this->data == null ) {
$this->data = array(); // actually do your query and get the data
}
return $this->data;
}
}
I'm a new bee to web development. I need to get data (some columns) from the job table and filter it according to the user name in the session and a status value (status is a TINYINT there for contains 0 and 1).
Here is my model:
public function show_work() {
$user_name = $this->session->userdata('Name');
$this->load->database();
$this->db->select('jbStageID, Description, StartDate, SpecialDetails, EstimateTime, Instrauctions');
$this->db->where('Name',$user_name);
$this->db->where('status','0');
$rset=$this->db->get('job');
$result=$rset->result_array();
}
Here is my controller:
public function employees()
{
$this->load->model('show_details');
$result= $this->show_details->show_work();
$data = array();
$data['inbox'] = $this->show_details->show_work();
var_dump($result);
echo "<pre>";
print_r($data);
echo "</pre>";
die();
}
The issue is I don't get values from the database but value null with empty array.
The result is like this:
Array(
[inbox] =>
)
You need to use the return to return the data as below in the model's last line:
$result=$rset->result_array();
return $result;
you missed $this->db->from
that means from table in sql query.
This should return a list of about five locations. It returns nothing with no errors. I've tested the sql using mysql workbench. It returns the data just fine. Right now I'm writing the back end so I'm not concerned with using views or the dataprovider. I'm just making sure my back end functions work. So with that in mind, how would you return the data retrieved by findAllBySql?
class CashLogic
{
public function AllLocations()
{
$model = new Locations;
$allLocations = $model->findAllBySql("SELECT name from locations");
return $allLocations;
}
}
class SiteController extends Controller
{
public function actionIndex()
{
$model = new CashLogic;
$data = $model->AllLocations();
return $data;
}
}
The findAllBySql() method returns an array of models. From your code it seems you only want the names of locations. An alternative method is
$AllLocations=CHtml::listData(Locations::model()->findAll(),'name','name');
This will return an array of the form array('name'=>'name','name'=>'name'). A better solution would be to replace the first name with the primary key of your locations table.