I've got a custom searchable member page on a WordPress site running s2member and I have a client that wants to use the mutli select box feature for the "category" data listed members can enter. My current code falls down here as the REGEX I currently use to select the category from the meta_value field only works with the single select box.
Here is the data as it appears in the database field:
s:8:"category";a:1:{i:0;s:17:"Business services";}}
Here is my current AND line in my SQL statement:
AND UMS.meta_value REGEXP '.*\"".$_SESSION['searchfield']."\";s:[0-9]+:\".*".$_SESSION['searchvar'].".\".'
How can I modify the above REGEX to work with the new multi option data? I’ve tried a few things but REGEX isn't a strong point of mine.
Thanks in advance!!
Related
I am using contact form 7 in my WordPress site for registration and trying to display the registration info in google data studio.
The field of form_value is like this:
a:9:{s:12:"cfdb7_status";s:6:"unread";s:9:"your-name";s:19:"John";s:10:"your-email";s:28:"john#gmail.com";s:9:"tel-phone";s:8:"20000000";s:15:"your-schoolname";s:2:"LA";s:10:"menu-which";a:1:{i:0;s:6:"Primary";}s:16:"text-schoolother";s:0:"";s:10:"menu-where";a:1:{i:0;s:3:"eDM";}s:10:"text-other";s:0:"";}
I hope to extract the data in the string like: John; john#gmail.com; 20000000; Primary etc.
I have try two way to work on this, the db should be 5.7 in mysql
Custom query, but i am not sure how to do it, i try to queryjson_extract() but it seem an invalid value because of the 'a:9:' in the beginning of the data ...
Filter it on google data studio, i try left() but the string of every result is not the same.
How can I perform it?
Thanks a lot, I finish in substring_index
SUBSTRING_INDEX(SUBSTRING_INDEX(form_value,'";',4),':"',-1) AS Name,
SUBSTRING_INDEX(SUBSTRING_INDEX(form_value,'";',6),':"',-1) AS Email,
SUBSTRING_INDEX(SUBSTRING_INDEX(form_value,'";',8),':"',-1) AS Phone
...
I'm sorry if my question sounds confusing.I just started learning web2py recently,in this exercise I'm trying to make a simple users management webpage with the admin can assign the users theirs work lists,note and deadline
db.define_table('auth_manager',Field('name','string',requires=IS_NOT_EMPTY()))
db.define_table('manager',Field('user','string','reference user.name'),
Field('workname','text',requires=IS_NOT_EMPTY()),
Field('deadline','date'),)
db.manager.deadline.requires=IS_DATE_IN_RANGE(format=T('%Y-%m-%d'),
minimum=now,maximum=now+datetime.timedelta(60))
I thought of adding the manager's username in auth_manager table using appadmin's new record function.This is my user table
db.define_table('user',Field('name','string',requires=IS_NOT_EMPTY()),
Field('password','password'),
Field('workname','text'),
Field('deadline','date'),
format='%(name)s')
I wanted to insert workname and deadline into user table right after I add those form on manager but I couldn't find any other methods except the update or update_or_insert functions but both don't work because those fields can't be empty and their ids aren't the same value and multiple references to a single table don't work .
One last question,I want to use web2py's RBAC but the first & last name fields are often unnecessary if I want to use a full name field is there other way to do it?
Sorry for the long post,I hope I made my question clear.
You can use the tables from auth and let web2py to handle everything in between.
The following code should resolve your problem:
db.define_table('manager', 'reference auth_user'),
Field('workname', 'text', requires=IS_NOT_EMPTY()),
Field('deadline', 'date'))
I am currently experimenting with Microsoft Access and was curious how one would accomplish this.
I know that one can add a prefix to an autonumber in the format option such as "EMP"000, and each autonumber would fill as EMP001, EMP002, and so on.
What I would like to do is have the "EMP" change dynamically so if my personnel table has them as a Manager for example, it would be listed as MGR003, MGR004, etc.
My thought was to have something like the following in the format section but again am still new to indepth access so please excuse my crude write up.
"SELECT FROM [PersonnelTable].[PersonnelAbbreviation] if [Add Task].[AddTaskPersonnelType]==[PersonnelTable].[PersonnelType];"000
So to recap, I have two tables one "Add Task" the other "Personnel". Would like prefix on Add Task AutoNumber to be based off the abbreviation I have in table Personnel.
Thank you Stack Overflow users!
Simply use a query (air code)
SELECT anydesiredfields, PersonellTable.PersonellType & Format(PersonellTable.PersonellID, "000") as FormattedID
FROM PersonellTable
INNER JOIN AddTask ON PersonellTable.PersonellID = AddTask.PersonellID
I am fetching results from a database table which contains the text of multiple pages.
These pages have links in their content.
I am trying to get all the links from the pages in a table, but I am also getting the unwanted text.
For example, this could be the content of a certain part of a page:
line 1: This is the link for lalalaal </a href="page5.html"> click</a>
line 2 if you want to go to page lalalala2 click
Now I only want the area starting from the <a href and ending at </a> in the result record. if there are more than 1 anchor tags in the text, then each anchor tag should be treated as a record.
the returned result should be like
ID value
1 ' click '
2 ' click '
I have tried the following queries :
Select * from [Database.tablename] where value between <a href and </a>;
Select * from [Database.tablename] locate '(<a href, Value)>0' and locate (</a>, value)>0;
but none of the 2 queries are giving me the wanted result...
This sort of text extraction is probably best addressed using regular expressions.
MySQL has some support (see here), but it could only be useful to identify which rows do have an <a></a> pair. Even identifying that there is at least one link inside a record doesn't help you extracting the (possibly many) links and treating them as different records themselves.
To successfully extract those links, at least according to my knowledge, you need a tool better suited to work with regular expressions. Most languages (Perl, PHP, Python, Java, etc.) support them, some natively, some using available libraries. You can select only records containing links (using REGEXP), and extract every link via code.
Another way of handling this would be performing the query on MySQL, exporting the results to a text file, and working on its contents with shell scripting (for instance, using sed under UNIX/Linux).
If you need it to be implemented using only MySQL, then my best guess is trying with a stored procedure (to be able to work on the results record-by-record.) I still cannot think of an implementation of such SP that guarantees detecting and successfully extracting every possible link inside a record as one record per link.
I search my sql table using in:
videos.category in ($categoriesSelected)
I pass through the categories based on what a user selects. Sometimes when a user selects no categories I want all videos to be displayed, Ive tried changing the $categoriesSelected var to * but no luck.
Will I have to do a seperate query taking out 'in' for when I want to display all, or is there a way to change $categoriesSelected to display all? Note, I do not want to just prefil it with the names of all my categories as this constantly changes via a CMS.
If your query is built dynamically and you happen to not escape the value of $categoriesSelected
you could try videos.category IN (videos.category).
Note: this is a dummy hack and you better rewrite the whole section of code that builds the query.
You must do a check to see if something is in $categoriesSelected - if yes then do your actual query, else do the query without the IN clause
Try putting in 'SELECT category FROM categories' for your $categoriesSelected.
Change category to be the field name that stores your category name.