I want to fetch data from a database with multiple id's in codeigniter.
Instead of one id, I want to use multiple id's.
$q = $this->db->select('*')->from('data')->where('FILTER',$a)->get();
return $q->result();
Not actually any errors.
Try this:
q = $this->db->select('*')->from('data')->where_in('FILTER',$a)->get();
return $q->result();
Related
I am working on a system where users can block other users. On the user class, there is a relation called "blockedUsers" which points back to the user table.
If I have a user, and I want to find all the users he has blocked, I do this:
ParseUser user = ParseUser.getCurrentUser();
ParseRelation<ParseUser> relation = user.getRelation("blockedUsers");
ParseQuery query = relation.getQuery();
List<ParseUser> blockedUsers = query.find();
In SQL, this would be something like:
select block.blockee
from block
where block.blocker = 'SomeObjectId'
This would give me the object_ids of all the users who were blocked by user 'SomeObjectId'.
In SQL, I could also reverse this, and say:
select block.blocker
from block
where block.blockee = 'SomeObjectId'
This would give me the object_ids of every user who had blocked user 'SomeObjectId'.
The question is, is there a way to do a query in parse that is similar to the second query? I have looked at ParseRelation.java, and there is nothing in there which is obvious. mongodb uses join tables, but I see no way to join backwards.
Any help?
Yes. It is possible. Something like this should do what you need:
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.equalTo('blockedUsers', blockeeUserObject);
List<ParseUser> blockers = query.find();
I am using REST api to fetch data from a SharePoint list.
I am able to get the lookup fields data using this query:
requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department.
However when I use this query requestUri = "/_api/lists/GetByTitle('Data')/items(6)" or this query requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department&$filter=ID eq 6" I am not getting the data from the lookup fields.
What could be going wrong here?
I tested with the endpoint, it works:
/_api/web/lists/GetByTitle('ListName')/items(1)?$select=ID,Title,Department/Title&$expand=Department
Compared the url with yours in original question, only append web behind /_api, it should be working.
The issue was found.
Figured out that I was fetching an item for which all the lookup fields were blank.
I fetched another item, and data was returned as expected.
I've an application, which uses Firebase. I have a new post adding. And when I make it, I do a number of operations in database, like:
Add new post info to Posts node
Add Id of the new post to Users node
Upload media to storage
etc.
So, for example, user can close application on step 2. How can I reset data on start of adding new post?
If I've understood correctly, Firebase transactions work on only one data table.
Main question is: how to make transactions on multiple data tables and storage in Firebase?
I believe you're looking for something like this: https://firebase.google.com/docs/database/web/read-and-write#update_specific_fields. It allows you to run multiple updates all at once to wherever you need. Here is a snapshot of the code:
var updates = {};
updates['/posts/' + newPostKey] = ...;
updates['/user-posts/' + uid + '/' + newPostKey] = ...;
return firebase.database().ref().update(updates);
So I have by entity framework 5 set up. I have a Customers table in the database. What would be most efficient way to get customers of a given zip code for example 94023? I have this:
var customersOfLosAltos =
(myDbContext.CreateObjectSet<Customer>()).Where(c=>c.Zip == "94023");
But, intuitively, that seems pretty inefficient because as I understand it, it basically retrieves all customers from the data source, and then filter it out by the given zip. It might be OK if I only have a few hundred customers, what if I have a million customers?
Any thoughts? Thanks.
as I understand it, it basically retrieves all customers from the data source, and then filter it out by the given zip.
Your understanding is wrong. Entity framework turns your code in to a SQL query, so what the server actually returns is the result for the query
select * from Customer where Zip = '94023'
If you changed your code to
var customers = myDbContext.CreateObjectSet<Customer>().ToList();
var customersOfLosAltos= customers.Where(c=>c.Zip == "94023");
then because of that .ToList() it now does a unfiltered query to the database then in memory filters on the client it to just the customers you want. This is why you want to try to keep your query as a IQueryable for as long as possible before you get the results because any tweaks or changes you make to the query propagate back to the query performed on the server.
To make your query even more efficient you could add a Select clause
var lastNamesOfCustomersOfLosAltos = (myDbContext.CreateObjectSet<Customer>())
.Where(c=>c.Zip == "94023")
.Select(c=>c.LastName);
The SQL server now performs the query (when you retreive the results via a ToList(), or in a foreach, or via a .AsEnumerable(), ect.)
select LastName from Customer where Zip = '94023'
I am taking the values from a search form in my application to build a dynamic query:
string queryString = #"SELECT VALUE USERS FROM ProjectDBEntities.Users AS Users
WHERE ";
There are two tables in the database, Users and Photo, table Photo has a column UserId that links to the Users table. A one to many relationship exists between Users and Photo.
After some iteration through the form values and adding System.Data.Objects.ObjectParameter values, I end up with following query:
SELECT VALUE USERS FROM ProjectDBEntities.Users AS Users
WHERE Users.CountryId = 2
Then I have this code:
System.Data.Objects.ObjectQuery<Users> usersQuery =
new System.Data.Objects.ObjectQuery<Users>(queryString, _db);
The usersQuery object does not contain the Image data for each Users. In my View I can iterate through the Users.Image but the Image count is always zero. Do I have to include or attach the Image data somewhere? How?
Just add an .Include() for the image property:
System.Data.Objects.ObjectQuery<Users> usersQuery =
new System.Data.Objects.ObjectQuery<Users>(queryString, _db).Include("Image");