Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm working on a front-end for a catalog database. So far it is going pretty good, but by the end of this I'll have probably a million rows of items in my database. I know this is more option based, but I wanted feedback on the best of way of doing this.
I was wondering if I should pull all records at once for a list and then use a filter type setup so it shows only items starting with A, or top rating items, then can click b and it would show all items starting with a b as option 1. Option 2 would be fetching the new data from the database upon request. So by default items starting with A will show then when the link/button for items b is click it will connect to the database and fetch those items.
Thoughts and options please!
PS I'm working with bootstrap/php/mysql/jquery/javascript.
Well, don't pull all million records every request.
See LIMIT and OFFSET http://dev.mysql.com/doc/refman/5.0/en/select.html
You should probably use an ORM or library that helps you with pagination
Make sure you understand SQL parameterization (for security)
I find that lists like catalogs are best served from search servers (like Solr) over databases, esp if you want search facets. MySQL does have text search though.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've read tons of questions who are in many ways the same as this one. But I just can't seem to understand how I am supposed to do this the proper way.
I've got one table with my pages.
And one table with portfolio items.
I want to be able to say to a portfolio item: You are linked to the welcome page now.
My approach:
In my pages table i've created a "items_linked" column. Inside this column the id's of the linked portfolio items get stored.
In the html of the 'edit page' I have a select with all my portfolio items, whichever I select gets stored inside the "items_linked".
I use the mysql UPDATE to get the information inside the database.
However this way I can't link a portfolio item to more than 1 page.
Because UPDATE removes the old information.
So I was guessing I needed a way to keep the old info, and add new info if the item is linked to a second page.
Can someone push me into the right direction?
Since we have no way of knowing what we are replacing I can only give you an idea of what to do:
UPDATE `table`
SET `myColumn` = CONCAT(`myColumn`, other_data)
WHERE some_condition_exists
This causes the information in myColumn to have additional data appended to it.
Here's the thing (caveat ahead): If you need one item to be linked to many items what I have described is not the way to go. You should have a table between the two you have already which will allow a one-to-many relationship between pages and portfolios. Please consider refactoring your database design.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Okay, so currently I'm creating a website from scratch for my small online shop and am stuck on where to even begin when it comes to my Products page. Currently, I have 1 page that displays all 50 of my products. I plan on expanding my products and do not want someone to be scrolling down the whole page. I would like to add multiple pages that you can click through and I believe I can accomplish this through Pagination. Now, this is the part where I get confused : say I only want 25 products to be displayed per page and I add a new item to the first page - how do items get 'bumped' to the page 2, 3 etc.? I would imagine there is some function to accomplish this, but the only way I can think of is doing this the brute force way of manually moving a product out of one page and onto another. Any suggestions??
Currently, my website is coded in all HTML / CSS and I currently just learned how to use PHP to mass edit certain areas of the website -- I am in the learning stages! Any suggestions would help. Thanks!
You need the help of a database to paginate your products in sets.
Basically, the database will have a "Products" table, each row in the table will represent a single product. You will use PHP to ask the database to retrieve the first/next N rows and then write out the appropriate HTML around each returned row to create a list of products.
There are lots of tutorials on the web to help you learn while you practice. Good luck!
There is no way to do that on static HTML web-site.
You need server-side script (e.g. PHP script) for splitting your product list by pages. By the way, you should store your data in DB and it should be done on the DB-side to not overhead your PHP side.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I would like to set up an online store and a point of sale application for a food coop.
My preference is php/mysql, but I can't find any projects which accomplish both these requirements. I was wondering if it would be possible to use separate store and pos apps and get them using the same product database.
The questions I have about this are:
is it a bad idea?
Should one of the apps be modified to use the same tables as the other or should there be a database replication process which maps the fields together (is this a common thing?)
is it a bad idea?
The greatest danger might be that if someone successfully attacks your online store, then the pos systems might get affected as well. E.g. from a DOS attack. That wouldn't keep me from taking this route, though.
Should one of the apps be modified to use the same tables as the other or should there be a database replication process which maps the fields together (is this a common thing?)
If you can get at least one of the two systems to use the products data in read only mode, then I'd set up a number of views to translate between the different schemata without physically duplicating any data.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a system where users can 'like' content. There will likely be many hundreds of these likes going on at once. I'd like it to be AJAX driven so you get an immediate response.
At the moment I have a mysql table of likes which contains the post_id and user_id and I have a 'cached' counter on the posts table with the total number of likes - simple so far.
Would I benefit in any way, from storing any of this information in mongodb to take the load off of mysql?
At the moment, I click like, and two mysql queries run - and INSERT into likes and an UPDATE on posts. If I'm in a large-scale environment in heavy read/write situation what would be the best way to go?
Thanks in advance :)
MySQL isn't a good option for something like this, as a large number of writes will cause scaling issues. I believe MongoDB's real advantage is schemaless JSON document oriented storage, and while it should perform better than MySQL (if set up correctly), I think you should look at using Redis to store counters like this (The single INC command to increase a number value is the cream on top of the cake). It can handle writes much more efficiently than any other database, as per my experience.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I just started learning PHP today and I have some conceptual questions regarding how I should use the language and accomplish specific tasks.
My question: Let's say I'm using PHP to build a CMS for a blog. On the home page I would like to have three articles show up that I have marked as "FEATURED" on the back-end in a field named is_featured.
Here is the solution I have come up with and I would like to know if this is possible with PHP, if it's practical, or if there is a better, more efficient way:
I would use a foreach loop to cycle through all $articles as $article and then check to see if that article has the value of FEATURED for the field is_featured.
In practice the articles would (probably, hopefully) be stored in a database in a table articles. You'd query the database for all articles ... WHERE featured = 1 LIMIT 3 ORDER BY publishing_date DESC, then loop through the database result set and output all found articles.
That would work, yes. However, this has the overhead of filling a potentially huge array with all the articles from your DB and then iterating through it to pick the featured ones.
For this kind of task, it's better to have the DB filter the results before sending them to PHP.
In general, try to do all your filtering of data in the database, as database are specially optimized for such queries. Loading them into PHP and then filtering the records is slower and less efficient.