Mongo: find element (id) in Array of Id's [duplicate] - php

This question already has an answer here:
How to find a document by embedded item in MongoDB PHP
(1 answer)
Closed 5 years ago.
I have an ID, and I want to get all documents that has this ID in array.
How can i get all documents that:
my_ID in {recipients.ids}
I think this is something like the "opposite" to $in.
Thanks.

If I understood correctly, this should do it:
db.your_collection.find({'ids.recipients': 'the_id_you_look_for'})

Related

Why have 2 values when i use query select in php? [duplicate]

This question already has answers here:
PHP PDO retrieves duplicate data
(2 answers)
Closed 1 year ago.
I'm newbie in PHP and when I use PHP to query select, I got 2 values, I realize it may be make slow if have 2 duplicated values.
So I want to ask about it and I also want to get just 1 values from select
thanks for reading my question.
here is picture:
It dipends on what your i guess sql query respondes to your query. However if you want cut down your result in sql you can use LIMIT 1
SELECT ...
FROM ...
WHERE ...
LIMIT 1

PHP Displaying PHP foreach values when some values have a space between two words coming from the DB [duplicate]

This question already has answers here:
return object value with space in key [duplicate]
(2 answers)
Accessing Class Properties with Spaces
(3 answers)
Closed 2 years ago.
This question was closed which is ok Take a look at the suggested questions. I would not have known to search what those are titled so dont just click away!.
I am not sure how to work with PHP foreach when the values it is pulling have a space in them inside the database.
Example - in the DB the following value exists and object in an array like - Number One. So I first tried:
foreach ($type as $value){
$value->Number One
};
echo $value->Number One
This above produced a string error.
I followed by using a non breaking space. Number One .
When I use this, all I get is a value of '00' which is incorrect. The value is actually '1'. So how do you handle an object in an array when there is a space in the object name as it comes from the DB?

PHP - get data From meta value [duplicate]

This question already has answers here:
How to use php serialize() and unserialize()
(10 answers)
Closed 5 years ago.
I have this record in data base row :
a:2:
{
i:2;a:2:{s:6:"amount";d:150;s:11:"description";s:53:"value1";}
i:3;a:2:{s:6:"amount";d:1800;s:11:"description";s:53:"value 2";}
}
Is it Json or What exactly ?
And how can i extract data from it ?
I want to get each amount and description values
It's serialized data. You can use unserialize() to turn it in to an array.

Return JSON Object with certain name [duplicate]

This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
php - deep search array of arrays and return only matching elements
(5 answers)
Closed 5 years ago.
I find this quite hard to explain as you can see in the title but let's say this is how my object looks like,
{
"success":true,
"objects":[
{
"name":"Stick",
"value":"wood",
"size":"large"
}...
]
}
Now I'm trying to get all the data where the objects name is Stick, so basically if it's "name" is stick it should return, name, value and size.

Extract multidemensional array string [duplicate]

This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 6 years ago.
I have multidimensional array string stored in PHP variable and I want to extract the keys and its values. Below is the given string which need to be split.
[{"cutoffTime":"1","refundInPercentage":"50"},
{"cutoffTime":‌​"3","refundInPercent‌​age":"70"},
{"cutoffT‌​ime":"6","refundInPe‌​rcentage":"90"}
]
How can I extract this?
Try this to have your work done
json_decode($string)

Categories