Find Character In Primary Key and Update a field - mysql

I'm working on a e-commerce website that uses CMS that uses MS Access 2000 database. The CMS generates the website pages on upload so there's no database online other than Perl files to control the shopping cart. The CMS allows the creation of duplicate products that can be placed elsewhere on the site
I have a table called PRODUCTS in my database. Whereby if a product is a duplicate of the original it contains ! in the primary key
Within the Product table I wish to turn off a setting for all the duplicate products only in the database.
I'm trying to create an SQL statement which would say..
FROM Products
Where Product_Reference contains the character !
Set Can_Be_Ordered_Online to False
Can anyone help?

In regular MySQL it will be something like this:
UPDATE Products
SET Products.Can_Be_Ordered_Online = 0
WHERE Products.Product_Reference LIKE '*!*';
It's hard to find MS Access 2000 docs online these days :(
Luckily, I've found this document about LIKE condition, therefore I've just updated my answer. % character is MySQL and other SQL-s wildcard, apparently in MS Access 2003 (and with some luck in MSA 2000 too!) the wildcard char are *, # and ?.
Nice history lesson :)

What you're looking for is something like that:
UPDATE PRODUCTS SET Can_Be_Ordered_Online = FALSE
WHERE Product_Reference LIKE '%!%'
If the ! is always at the end or at the start, you can remove one of the %.

Related

MS-Access Looking up and updating records based on values in form

I've learned a lot in Access over the last month or so but am now have trouble resolving an issue that I don't know how to approach. I'm sure there's a simple solution but I need help being pointed in the right direction. Here's the background:
This problem deals with three forms:
frmProject - Lists project details it has a
subfrmMilestones - Milestone details
frmProjMsgBox - Collects info to pass to Project table
I have it set that when I click OK on ProjectMsgBox it passes the information to the Project form and starts the creation of a new record.
tblProject stores all details related to projects
tblMilestones stores all details on milestones, contains key for tblProject
tblMilestones_Inf stores a list of common milestones based on project type, has key for tblProjectType, which is on tblProject
My Problem -
When I click okay on the ProjectMsgBox form, I would like it to also look up milestones from tblMilestones_Inf and insert into tblMilestones. I also need to assign the Project_ID that on the form to the creates. What is the best way to go about this?
I've tried a few things in VBA but haven't had success. I can create a query that pulls the milestones in but don't know how to update the milestone table with the relationship to the project table.
I can provide more details but wasn't sure what is helpful and what is not. I'm more or less looking for a resource (or keywords to search) so I can figure this out on my own
Thank you!
UPDATE:
tblProject has 1 to many relationship with tblMilestones
tblProjectType has 1 to many relationship with tblMilestones_Inf
Once I hit okay on the frmProjMsgBox it fills out text boxes that have controls on frmProject to create the parent record (i think that's the term) in tblProject. This works well. I would like access to go out to the tblMilestones_Inf and match the project type (child record?). It would then add 4-5 records based on matching ProjectType on the Milestone_Inf table. I don't want code, but maybe actions/keywords to lookup so I can figure this out on my own. I'll post some of my code later that tries to achieve this.
You might want to look into Query Defs, you can use those to change the SQL statement of your queries from VBA. So if you have something like:
MyQryDef.SQL = "SELECT * FROM MyTable WHERE MyIndex = " & MyControl.Value & ";"
and your control value is set to 5, you then use the execute statement and your Query SQL will then read:
SELECT * FROM MyTable WHERE MyIndex = 5;
There's a few more lines you will have to look up to make this work, but this is a very basic example.

replacing multiple table information in mysql

I've recently been given the task of maintaining a sports team's website and have encountered a problem which I cannot find the answer.
It uses Nucleus CMS which is fine and I'm used to it, unfortunately, the domain name has changed and all links and files within the site stored in the mysql database are now out of date and not the correct one.
I am able to manually alter each item using the admin panel of the CMS, but with several thousand posts, that task is daunting.
Is there a way I can do a "replace" domain1.com to domain2.com in the item table in one process through the mysql database?
Forgive me if I'm not using the correct terminology.
Try this:
UPDATE tbl SET domain_name = 'domain2.com' WHERE domain_name = 'domain1.com';

Can you produce a dynamically generated field in MySQL at the server lever?

We have an older system that's being replaced piecemeal. The people who originally designed it broke US telephone numbers for our clients up into three fields: phone_part_1, phone_part_2, and phone_part_3, corresponding to US Areacodes, Exchanges, and Phone Numbers respectively.
We're transitioning to use a single field, phone_number, to hold all 10 digits. But, because some pieces of the system will continue to reference the older fields, we've been forced to double up for the moment.
I'm wondering if it's possible to use MySQL built-in features to reroute requests for the old fields (both on read and write) to the newer field without having to change the old code (which is in a language nobody here is comfortable in anyhow.) So that:
SELECT phone_part_1 FROM users;
Would end up the same as
SELECT SUBSTRING( phone_number, 1, 3 );
To be clear, I want to do this without manipulating the individual queries. Is it possible? How?
You could define a VIEW:
CREATE VIEW users AS
SELECT SUBSTRING( phone_number, 1, 3 ) AS phone_number, ... FROM real_users;
Then you can query it as if it were a table:
SELECT phone_number FROM users;
But that would require your "real" table to be stored with a distinct table name. You can't make a view with the same name as an existing table.
When you're ready to really replace the table with the new structure, then you can use RENAME TABLE to change tables as a quick action (no table restructure required).
Have you looked into views? A view will take the place of a new table for now, providing a way to have your new structure, but still access the data in the original tables. Once you are ready for your final move, you can implement new tables and do a mass conversion of any remaining data you haven't done yet. Or you can go in reverse, which is what it sounds like you really would prefer.
Create your new table, convert your data, and set up a view that mimics the old structure.
Views in MySQL: http://dev.mysql.com/doc/refman/5.0/en/create-view.html

"is_visible" flag location for Woocommerce products attributes

This matter is driving me crazy as after wasting days going through my DB I've still been unable to find out an answer to the following question:
Where is the flag "is_visible" stored on the mysql DB for the attributes of Woocommerce products?
I checked all the tables 1000 times but I can't understand where and how the flag option "attribute visible on the product page" is stored on the Wordpress DB.
Thanks!
Enrico
the data is sotered in the postmeta table. However it is not quite straight forward to handle it. If you pick a product and do a search for the product ID as post_id you will see a record with the meta_key _product_attributes. In the meta value you will find a serialised array of the attributes including is_visible.
Just be careful because if you simply edit it in phpmyadmin you can mess stuff up badly. If you don't know what a serialised array is google it.
In case someone is searching for this in the year 2022 or later: In the meantime woocommerce isn't storing this value in the post_meta table. Instead there is a taxonomy called "product_visibility" with different states (exclude-from-catalog, exclude-from-search). In the "term_relationships" table is stored which of these values is associated with a product.

Batch add tags to posts via phpmyadmin - wordpress

How would I go about batch assigning tags to posts via phpmyadmin? I have a custom table in my database that contains the postID and one column with a comma separated list of keywords for each post/record. I want to use the keyword column as values for my tags for each post.
Is there any way for me to get those tags over to the wp_term_relationships table using an sql query?
Right now I already have each post assigned to one category (and some posts assigned to two categories)...if that makes any difference....I am dealing with almost 200,000 posts.
Thanks for the help!!
I thought I could do this with sql queries but that is just over my head..so I did some extensive searching for plugins (free plugins that is...).
I came up with this, which is working....
Installed the 'WP Post Corrector' plugin, it is old and not updated anymore but it is working with my 3.5.1 wordpress. I have a massive csv file with 2 columns (ID -> which is the same as my wp post ID, and post_tag -> which is a list of comma separated tags). I split the file up into smaller chuncks so php or the server wouldn't crap out (http://sourceforge.net/projects/splitcsv/) - I made each file have 5000 records.
Yes, it took me about an hour to upload about 40 files, but now it is done.