I'm attempting to get the results of a database table and echo the query results.
Here is my code:
$queryDB = $this->db->select('*')
->from('dr_template_relational')
->where('value_id', $categoryDetails['value_id'])
->where('subcategory_id', $categoryDetails['subcategory_id'])
->get();
echo "<br>";
echo "here is queryDB";
echo($queryDB);
echo "that was it";
$queryDB doesn't echo even so I'm sure the data is there. I'm wondering what I'm doing wrong. I'm not getting an error, but also don't get any output with echo($queryDB); on screen it displays:
here is queryDBthat was it
Right now, your approach is just echoing out the instance of the query.
In order to see the query results, you need to create them. There are several CI functions like result() and row()
at the end it could look like this:
foreach ($queryDB ->result() as $row){
echo $row->value_id;
echo $row->subcategory_id;
}
see Generating Query Results
hint: in order to see the generated query you could use
echo $this->$db->last_query();
Related
I want to display data from cv table where user_id is $request->id.
Also, filtering is done so i have to put lots of orWhere.
Because of this my code is not working as expected.
Sorry question is a little bit confusing.
$search = $request->input('search.value');
$results = cv::with(['industrySegments','jobLocations','jobPositions','languages'])->where('user_id',$request->id);
$results->orWhere('name','LIKE',"%{$search}%");
$results->orWhere('gender','LIKE',$search);
$results->orWhere('contact','LIKE',$search);
$results->orWhere('contact2','LIKE',$search);
This code doesn't work.
whenever i type something in search button it displays data that is not supposed to be display.
I want to display only the data whose user_id is $request->id.
i think what you wanted to do is advanced where
your query will be like this
$results = cv::with(['industrySegments','jobLocations','jobPositions','languages'])->where('user_id',$request->id)->where(function($q)use($search){
$q->where('name','LIKE',"%{$search}%")->orWhere(..........;
})->get();
therefore you can play around with where / orWhere
Test next code:
$results = cv::with(['industrySegments','jobLocations','jobPositions','languages']);
if(!empty($request->id))
{
$results->where('user_id',$request->id);
}
else
{
$results->orWhere('name','LIKE',"%{$search}%");
$results->orWhere('gender','LIKE',$search);
$results->orWhere('contact','LIKE',$search);
$results->orWhere('contact2','LIKE',$search);
}
I get the output of the values as following in the postman.
[{"currentVersion":1.1}]
How can i get output in simple form as: 1.1
$currentVersion = DB::table('app_Version')
->select('currentVersion')
->get();
echo $currentVersion
How can i get output in simple form as:
1.1
You would do:
echo $currentVersion[0]->currentVersion;
However, if you know you'll always have one record, you could simplify this a bit with:
$result = DB::table('app_Version')->first(['currentVersion']);
echo $result->currentVersion;
In the controller, I store some data in an array.Then I want to send it in myelectionlist.blade.php
$my_election=[];
$i=0;
foreach ($election_list as $election_list)
{
$my_election[$i]=DB::table('election')
->where('id','=',$election_list->election_id)
->get();
$i++;
}
return view::make('myelectionlist')->with('election_list',$my_election);
I check with
return $my_election
It works fine. But In myelectionlist.blade.php when I write
#for($i=0;$i<sizeof($election_list);$i++)
{{$election_list[$i]->election_name}}
#endfor
It does not work.
Undefined property: Illuminate\Support\Collection::$election_name
happens, How to solve the problem?
There's a combination of problems that I would fix in order to bring clarity to your code and explain to you the problem. First of all in your code you have:
foreach ($election_list as $election_list)
I'll rename the variable for you to see:
foreach ($foo as $foo)
So what this does is that inside the foreach loop you will get all the values one by one, like expected but every time you store it to the initial variable. And once you are done with the foreach or break out of it earlier the $election_list will have the last used value. It might have unexpected results if you're trying to use the same $election_list later again. So I would suggest to use a differet variable names perhaps like $election_list as $election
Next, it's a little bit unclear why you would track the $index of the new elements by yourself. Instead you could just push into the array like this:
$my_election[] = $newObj
Actual error message:
Now for the actual error message: ->get() returns a Collection. So in the end you have an array full of Collections. So inside the for loop when you do $election_list[$i] - this will actually be a Collection object instead of the Model and thus the exception.
->get() will always get you the collection. For example with methods like ->first() and find/findOrFail you would get a single model. These functions might also be more appropriate to use since we are requesting with and id anyway.
Additionally, if this question is not a simplified version of your code then what I think you should actually do inside the controller:
$my_election = DB::table('election')
->whereIn('id', $election_list->pluck('election_id')) // pluck will give all the id's
->get();
This way you have a Collection of models assigned to $my_election.
Is there a Syntax to display total clients in WHMCS (as a number)? If not, is there any way of doing this?
You can use this ode within your template files.
Just put this lines of code within your /templates/yourtemplate/yourfile.tpl
{php}
$query ="SELECT COUNT(id) from tblclients ";
$result = mysql_query($query);
$data = mysql_fetch_array($result);
echo "total clients :".$data[0];
{/php}
You can use getcontacts command for getting the total numbr of clients in WHMCS. You might want to have a look at this document:
http://docs.whmcs.com/API:Get_Contacts
I am getting MLNumbers from RETS Server but now I need to get all the fields of all the MLNumbers and store into my database. Could anybody help me to write query to get the whole property Object.
If you have all the Listing Numbers then you just need to write a search query to pull all the results back and process the results. I haven't ever seen a field name MLNumber but you will have to figure that out:
<?php
$search = $rets->SearchQuery("Property","RES","(MLNumber=11111,22222,33333)");
while ($listing = $rets->FetchRow($search)) {
echo "Address: {$listing['StreetNumber']} {$listing['StreetName']}, ";
echo "{$listing['City']}, ";
echo "{$listing['State']} {$listing['ZipCode']} listed for ";
echo "\$".number_format($listing['ListPrice'])."\n";
}
$rets->FreeResult($search);
I think this should return the results you need. You will need to figure out the Resource/Class/Field name you need to use for your SearchQuery().
More PHRETS examples here.