I'm not a professional, but I'm messing around with wordpress trying to customize it the way I want it to work...
I've a necessity to add additional data to single-posts, specifically a restaurant menu, each post will have unique menu displayed in sidebar.
Single post is a single row in wp_posts table.
I'm adding additional info using wp metabox functionality, which has its own table called wp_postmeta.
This table is different from wp_posts because it can contain many rows of meta information for a single post.
My questions:
Is this implementation slow?
Will it cause problems if db grows?
Why would wp guyz implement this in this way?
Would not it be wiser to have single meta column and multiple rows per post?
I see that you have "price_list_heading", "price_list_category","price_list_heading1", "price_list_category1","price_list_heading2", "price_list_category2","price_list_heading3" and "price_list_category3" I don't know why, but I think you shouldn't do that, you need to create a relational table with index (I don't know if Wordpress let you do that)
it'd will look like: this will depend of the cardinality of your APP
Let's say that 1 post meta can have multiple categories and multiple categories can be with one postmeta (cardinality N:M)
Now If one post can have multiple categories and one category can have only one post
Where wp_postmeta_copy1 is a FK from ws_postmeta table (id)
Please take a look to this documentation :
http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model
http://www.inf.unibz.it/~franconi/teaching/2000/ct481/er-modelling/
http://searchsqlserver.techtarget.com/definition/entity-relationship-model
Related
I'm trying to migrate from a custom CMS to Wordpress, but retain as much as possible from the structure of the old CMS. The problem is the old one had separate DB table for media and wordpress stores media alongside posts, in the wp_posts table.
In the old cms, images had independent IDs from the post ID's and I would like to keep this structure. (10TB of media, 500K articles :) in the DB ).
I'm trying to make a trigger that, when a query hits the wp_posts table with "type=attachment", fetches the result from the media table and returns it, ignoring the results from the wp_posts table.
No luck yet...
Has anyone did this before? All (almost)successful examples online are on PostgreSQL...
Thanks,
Silviu
I know, there already is similar questions, but I can't find a good answer at my problem.
I'm developing a social network, I have all my users in a table, but each users must be able to save multiple post from the website.
My Question is:
How can I store all the saved post for each user without creating a new table for each users. I know this is bad to do this, so I'm looking for an alternative
If I understand you correctly, you just need a middle table (for example names user_post) that have 2 columns : user_id and post_id
this is a simple implementation of a many-to-many relationship
You only need a table to store all posts call it posts table with structure like this:
|post_id|user_id|title|content|etc..|
So you can do something to save posts and identify them by user_id.
It's called one-to-many relationship, you can search more about database relationships.
I am developing a website by using ASP.NET and backend is MYSQL. PHP users If you dealt with this please contribute your idea also.
In my website users can post articles and articles are categorized.
Currently I am using below database structure.
When ever a user post an article to the website common things for article (title,description) are stored in the header table and specific details are store in specific category table.
But let assume that in a given instance category 1,2,3,4 have 100,000 records in each category. by simple math we know that the header table contain 400,000 records. Understood?
I am maintaining a user account and when an user log to his account he can view what are the articles are posted into categories and I am showing only titles of the articles. This is possible with no joins because I retrieve those from header table.
Ok. So those category and header tables are main production tables. Among those Header table is the busiest one because no matter what category you choosing it is use by every category table.
So day by day this header table is increasing.
This is the approach currently I am using.
This is my 2nd approach which is just an idea.
Take a look at this image.
In here I am maintaining 4 header tables for each category. So those header table will contain only the data of each category. And I am maintaining a main header table for user account process. This table will also contain title as well as what is the equivalent header table for the article. So at this time Main header table is not a production table. It is access only from user account. When user select category 1 in articles display window he is only dealing with that category 1 table and equivalent small header table.
So which is best? Do I need to worry about my current approach in future when I am dealing with massive amount of records?
(Assume database schema of these header tables will not change frequently. So forget about difficulty of maintain. I will handle it. My main target is the performance. I am using bigint datatype for the primary keys of every table. I used indexes)
Give me an intelligent, Long term, Business wise answer who already dealing with massive data storage. Provide me any links to refer and backup your answers please. Thank you very much.
I'm using the WP-Property plugin for an estate agents site. They want to use RightMove to display their properties as well, so I'm looking for a way to export the post type 'property' with all its related meta data.
Most of the data for a property is in the posts table, but things like the number of bedrooms, price etc are in the post meta table.
I'm not much of a back end coder, so I think I need an SQL query that will join the two tables together?
I have to convert it to a BLM file for RightMove, but I'm taking it one stage at a time, so getting the data I need out is what I need to do.
Is anyone able to point me in the right direction?
Thanks
Yes you need to write a join where the post_id of postmeta table is equal to the id of posts table
The website I'm building has a table which stores all the information of uploaded images on the site. These uploaded images can come from different resources such as a guestbook, news section or an item from an agenda.
Ofcourse I want the image to inherit the rights of the resource it is part of. For example: if user A isn't allowed to view the guestbook I don't want him to be able to view an image posted on the guestbook by going to image/view/id/12 (which would be the image request used it in the guestbook).
What I have now is that the system remembers the resources used (in this case the guestbook) the image-id is coupled to the resource-id. However I don't know to which guestbook post the image is connected (I do ofcourse know it the other way around).
Is there a way in SQL to connect one table field to a field in another table, where which table I connect to can vary based on one of the first table's field values?
In my case I would like to connect an image to a resource this could be a guestbook post in the table gb_posts or an agenda item in the table agenda_items.
Or is this all a stupid way of solving the problem and should I not use one table for the uploaded images but keep the image attached to the resource (as a column in the table for example)? It sounds like using one table is at least a lot slower in use (but I would have a great overview of all the images in one place).
I hope you guys can help me out.
EDIT: extra explanation: db model
I will try to explain how it all works the best I can.
First of all: I use Zend Framework, and therefor I also use Zend_Acl for working with priveleges.
My DB structure:
- Users are connected to roles (directly or by being connected to a group that is connected to a role)
- There is a table resources containing all the resources which is connected to priveleges. For example: guestbook is a resource, view or edit are the priveleges. Next to the controllers/actions there can also be other resources in this table such as a category within the agenda or a file location.
- roles are connected to a privelege
When for example the guestbook is requested for viewing I can check if the user is allowed to.
In short something like:
users -> roles -> priveleges <- resources
When a user adds a guestbook post with an image, the used resources (in this case guestbook is saved):
guestbook_posts -> images -> resources
I hope this explains my DB model for a bit, if it doesn't I will try to create an image of the tables.
I have to admit I'm failing to completely understand the model you wish to implement, but there is an interesting quote...
However I don't know to which
guestbook post the image is connected
(I do ofcourse know it the other way
around).
If you know an association one way, you should be able to use the associaton in both directions? I'm assuming you have a table that includes "post_id, image_id", or something?
It may be that the table is only indexed post_id first, in which case querying that table by image_id may be slow, but then you can just include a new index with image_id first?
If you can give examples of the table structure you have at present, and an example of the query you can't fullfil, we may be able to help you further.
Sounds like you want a foreign key constraint.
Update: Completely misunderstood the question, apparently.
There are two approaches here:
As it currently stands, there is nothing in the schema that would prohibit linking the same image from multiple resources. If that is desired, then a foreign key constraint and an index for the backreference is probably the best solution, although it will not scale well, and requires additional computation (because the rights on the image need to be the union of the rights of the refering resources).
The alternative is to create some kind of inheritance schema, where there is a table listing "resources" (that effectively just contains identifiers) that is referenced as a foreign key from the actual resource tables and the images table; the only constraint that cannot be expressed in plain SQL is that different resources may not share the same identifier.
Create two SELECT clauses, each having the correct joins to the correct tables, and then combine the output of the two SELECT clauses together using a UNION statement.
SELECT field1, field2
FROM table1
JOIN table2 on table1.PK = table2.FK
WHERE table1.selector = 1
UNION SELECT field1, field2
FROM table1
JOIN table3 on table1.PK = table3.FK
WHERE table1.selector = 2