regexp to find after 4th occurrence - regex

I using REGEXP in wp_query.
I am storing post meta as 20181020 (yyyymmdd)
so basically I want a REGEXP so that I can filter if user enter 10 (mm) in filter box
currently I am using this '^'.$date but this only works if user entered yyyymm format.
I want to search this if use enter value in either yyyy or mm there is no need for dd.
I want to filter based on user input.
User will select month or year,
for example, if user select Dec month then i will get response 10. Then i pass this value in meta_query.
here is the meta query. But in this issue is data stored in post meta is in yyyymmdd format. So I want a regexp where I can query to 4th occurrence.
$args = array(
'post_type' => 'achievements',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'achievement_date',
'value' => '^'.$date,
'compare' => 'REGEXP'
)
)
);
$the_query = new WP_Query( $args );

I figured it out.
i just need to use this ^.... expression. This will skip first 4 characters.

Related

Select list display issue

Good morning,
within Oracle Apex Application Builder I'm trying to create a order product page which displays products from a product table, shows a select list which a user can use to define the quantity in which they want to order. Using a classic report to display my code, the declared table columns were generated and outputted on the report, however the select list column only shows the html syntax used to create a select list and not the actual drop down select list with values.
Here is the code:
select p.product_id,
p.product_name,
p.product_price,
apex_item.hidden(1, p.product_id) ||
apex_item.hidden(2, p.product_price) ||
apex_item.select_list(
p_idx => 3,
p_value => nvl(c.c003,'Add_to_cart'),
p_list_values => '1,2,3,4,5,6,7,8,9,10',
p_show_null => 'YES',
p_null_value => 0,
p_null_text => '0',
p_item_id => 'f03_#ROWNUM#',
p_item_label => 'f03_#ROWNUM#',
p_show_extra => 'NO') "add_to_cart"
from prod p, apex_collections c
WHERE c.collection_name (+) = 'ORDER_ITEMS'
and c.c001 (+) = p.product_id
Can someone explain why this is happening, how to correct my issue and if there are better ways to implement a select list; as I need this code to work for my project?
Thanks in-advance for the help!
In Builder, navigate to that column so that you'd see its properties. Scroll down to Escape special characters and set it to "No". Then run the report and see whether there's any improvement (should be).

Select sum and dynamic where statement query in Rails 4

I have this below statement in my controller and I want to know how to rewrite it in Rails 4
Entry.find(:all, :conditions => [#conditions.keys.join(" AND "), *#conditions.values],:group => "user_id", :select => "SUM(time_spent) AS total_spent")
The condition has the user_id information in it like "user_id=?".
The statement is trying to find the entry for a particular user id and sum the time spent for the user id and group by user id.
For example you can use it
realations = Entry.where(user_id: [1, 2, 3]).select("SUM(time_spent) as total_spent").group(:user_id)
After that you have relation with which you can work
realations.each do |i|
puts i.total_spent
end

Doctrine 2 specific fields selected via querybuilder is not accessible using getter method

When I use doctrine 2 query builder as below to create a resultset:
$queryBuilder = $this->orm->createQueryBuilder();
$queryBuilder->select("s.id","partial s.{id, name, user}","s.name","concat(u.firstname,' ',u.lastname) fullName")
->add('from', 'Application\Entity\Schools s')
->leftJoin('s.user', 'u', 'WITH', 'u.id = s.user')
->getQuery()->getResult(Query::HYDRATE_ARRAY);
echo "<pre>";
print_r($dd);
die;
It gives following data:
Array
(
[0] => Array
(
[0] => Array
(
[id] => 1
[name] => DAV Public School
)
[id] => 1
[name] => DAV Public School
[fullName] => Manu Sharma
)
[1] => Array
(
[0] => Array
(
[id] => 2
[name] => Delhi Public School
)
[id] => 2
[name] => Delhi Public School
[fullName] => Vipul Sharma
)
)
So when I try to fetch its value using getter method:
$result->getName() doesn't work but I have to use $result[0]->getName().
and error says:
Fatal error: Call to a member function getName() on a non-object
How to choose specific fields inside queryBuilder's select method so that main array values must be accessed using getter methods. Why its not working. Is there anything wrong with my select query.
What is the benefit if specific selected fields can't be accessed using getter method. I believe I'm doing something wrong but it doesn't strike my mind.
Note: While using $result, I removed array_hydrate, that is I'm passing object and hence expecting getter methods to work properly.
The problem you're having is caused by adding additional fields to the SELECT clause. That's causing the result to put the object at index 0 to be able to add additional fields like fullName that you don't have in the entity to the result set.
As far as I understand, all you want is to have a method to get the full name of each user. Instead of solving that problem at the query level, you better just add a method to the User entity:
public function getFullName() {
return sprintf('%s %s', $this->getFirstName(), $this->getLastName());
}
And then just select users the usual way:
SELECT u FROM User u
You can now get the full name of the first user the following way:
$result[0]->getFullName();
You don't need partial objects here. Partial objects have completely different use cases.

CakePHP find list with group name same as data name

I have to show a select box with the different movie genres grouped by general genres.
To do so, I'm using the CakePHP default method find('list',...).
My database table for movie genres is done like so:
|_id_|_name_________|_general_genre_|
| 1 | Action | Action |
| 2 | Martial arts | Action |
| .. | ............ | ............. |
The problem is that if the group has the same name as the data (e.g.: "Action") the data is not shown in benefit of the group name.
So my select box looks like:
Select a genre
- Action
- Martial arts
- ...
And what I would like is:
Select a genre
- Action
- Action
- Martial arts
- ...
Of course, the reason is, it's not possible to select a group item.
Thanks in advance!
Ok, after some more research I finaly get the answer.
This is an attribute to add to the Html->input() method. This attribute is showParents.
So, if you want to make a select box with groups and have, inside this group, items with the same name that this group, you have to do something like this:
Select the list with the groups:
$options = $this->TableName->find('list', array(
'fields' => array('id', 'name', 'group_name')
));
Show the select input:
$this->Html->input('InputId', array(
'type' => 'select',
'options' => $options,
'showParents' => true
));
Hope this can help ;)
This is expected behavior. Use the showParents option when generating the form element. The API even has an eg. for this case which you failed to check :)
You can override the default fields that a find('list') returns (which are the primary key and the displayField) by your own fields, by setting the $options['fields'] option. These can be more than two fields if you need to. This should come close to what you need:
$this->Genre->find('list', array(
'fields' => array('id', 'name', 'general_genre')
));
This will return an array like:
'Action' =>
1 => 'Action'
2 => 'Martial arts'
You should be able to use that in a dropdown.

Symfony2: How can I list table elements in a FormChoice, separating them by some property

Is there any way to fetch objets from the DB and list them by Category? I have a table Artist which have a Genre and each Genre have a Category, so when I'm choosing Genre at new Artist creation I would like to see them separately by each one Category. I recall that in previous versions you could do something like:
$this->widgetSchema['genre_id'] = new sfWidgetFormChoice(array(
'choices' => array('-- Select --',
'-- Category1 --'=>Doctrine_Core::getTable('Genre')->getGenres('Category1')),
'-- Category2 --'=>Doctrine_Core::getTable('Genre')->getGenres('Category2')),
'multiple' => false, 'expanded' => false
));
And the result was a drop down with 'CategoryX' in bold, followed by respectively genres.
After a deep search all I've found is:
->add('group', 'entity', array(
'class' => 'Vendor\MyBundle\Entity\Group',
'label'=>'Group:',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('g')
->... // whatever you want to do
}
))
I think that is what I need, but have no idea on how to adapt it to what I'm looking for.
Many thanks.