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 8 years ago.
Improve this question
As part of a bigger project, I'm building a reporting application which analyses business data. The aim is to have default datasets and also allow for users to upload their own datasets.
I'm building this in PHP however I'm not sure what the best database is to use. MySQL is great and usually my first pick, but this is application does not really require a relational database for the datasets. Datasets could be thousands of columns and millions of rows. Getting this to work MySql is quite a challenge.
I've seen HDF5 which seems like a good database though not very well supported from a web application point of view.
Do you have any other suggestions for a database that can store such large datasets?
P.S - I should clarify the reason for the title.... I need to be able to allow users to upload datasets. The only way with MySQL would be to allow for a table to be created each time the users uploads a dataset. Doesn't really sound very good.
You should look into NoSQL databases. That sounds like what you are looking for. With NoSQL you don't have to create databases but store what ever and still be able to search the data fast.
If I understand you correctly, you need to create a sub table ( or something similar to this ) and store the custom fields in there:
Table name: custom_fields
+---------+----------------+----------+
| user_id | field name | value |
+---------+----------------+----------+
| 10 | favorite_sport | hockey |
| 10 | favorite_food | hot-dogs |
| 20 | sisters_name | Ashley |
+---------+----------------+----------+
And after this, just join the data together and show what you need.
Related
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 6 years ago.
Improve this question
I am creating a system where users (who are identified by a user id number) will be allowed to vote on posts (think Reddit, StackOverflow, etc).
Users can vote a post up or not vote at all on it.
The number of votes on a given post can easily be stored within the table containing the posts.
Keeping track of who has voted, however, is a different task entirely that I'm not sure how to approach.
I was thinking I could have a table that would have two columns: user id and post id.
When they vote on a post, I add their user id and post id to that table. If they unvote, I remove that entry from the table.
EG:
User ID | Post ID
1 | 3949
1 | 4093
2 | 3949
etc...
Is this a reasonable solution?
Yes this is reasonably simple and easy solution to the problem. You can do the same for your comments(if you like to). In your MAIN_POST table assign a post_id and use this same post_id in other tables (comments(post_id, user_id, post_comment, comment_time) and votes(post_id, user_id, vote_status(you can use 1 for vote up and 0 for vote down))). It will complicate your sql queries, to retrieve data, a little but you can do it. And on android side there are alot of tricks to handle and furnish this data in application and you can make this vote(like) and comments idea just like facebook (YOU for your comments and likes and NAMES for others).
I wouldn't remove rows from the table. I understand why you would want to do that, but why lose the information? Instead, keep a +1/-1 value for each entry and then sum up the values for a post:
select sum(vote)
from uservotes
where postid = 1234;
And, I agree with Rick that you should also include the creation date/time.
Using an 'in between' or 'joining' table is a perfectly acceptable solution in this case. If relevant you could even add a timestamp to the relation and show to the user when a user has upvoted something.
Also it is important to take care of proper Indexes and Keys to have your table structure also perform properly once the dataset grows.
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 8 years ago.
Improve this question
I am currently trying to get values from tables I have in a webpage into a database using PHP. However, the order of the values inside each box is important, so I want the first box to be ranked 1 and the second box to be ranked 2 and so on... There is no limit to the number of items in each box. There may be as many as 100 or 0. Each item in each box is dragged from a bank of items into the table, which represents a topic. The tables are the output of the interface.
So example table:
Rank1
Rank2
Rank3
I've currently tried dumping the entire page once the user fills it in into a text file and parsing it from there but i'm looking for a more functional and practical way of doing it.
If I understand your goal correctly, you have two sections on your webpage. A word bank and a <table>. A user can drag and drop items from the word bank to a cell in your <table>. Next you want the order of the contents of the cell to be preserved when the data is saved to a database-table.
Given the description you have provided, it seems you may be new to using databases. It is not a problem but you will need to do some study on how databases work and how to use them.
Again, if I understand correctly, your <table> looks like the following:
| topic-1 | topic-2 | topic-3 |
-------------------------------
| ---A--- | ---J--- | ---V--- |
| ---B--- | ---J--- | ---X--- |
| ---C--- | NULL | ---Y--- |
| NULL- | NULL | ---Z--- |
To move this into a database you need to create a database, and some table, for example MyDataTable. Next that table may have three columns: id, contents, category.
Here is some info on Mysql Insert.
INSERT INTO MyDataTable(`id`, `contents`, `category`)
VALUES (1, A, Topic-1)
You will need to format that call to work correctly via php, but that is the general idea. In your php code you will need to iterate over the elements in the order you want, and you can use the id to refer to your order... Alternatively you could add another column to your database-table and have that refer to your order, which would allow you to use some other value, perhaps auto-increment, as the primary key.
I would recommend becoming comfortable with MySQL if you aren't already, before tackling your project's specific needs. Namely, INSERT, DELETE, UPDATE, SELECT and WHERE will almost certainly be necessary MySQL functions.
One resource I found very helpful in grasping MySQL is this book, SQL Antipatterns: Avoiding the Pitfalls of Database Programming .
Using the phpMyAdmin page can be very helpful in debugging SQL queries, once the query syntax is correct, you can translate it to php and incorporate your dynamic variables. Also if you store your sql-syntax in php as $sql, using var_dump($sql) can also be a great help when debugging sql syntax.
In programming, iterate over, typically refers to creating a for-loop to iterate, or step through 1-by-1, each of the items of an array or similar container.
$MyArray = array();
$MyArray = GetTableContents(); //You have to write this function.
for ($idx = 0; $idx < count($MyArray); $idx++)
{
// do my stuff, like, Insert into my DB-table.
}
In order for the code above to work, you need to fill MyArray with the contents from your <table>. In the example code above, the $idx, could be used as your id.
In addition to MySQL, it seems it would also be worth your time to learn more about php programming. Read simple tutorials, how-to's, and books. There are numerous resources on the internet about php. One such example is here.
I hope this is helpful.
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 8 years ago.
Improve this question
Such a good day, everyone is well, the question is the following.
I think a couple of tables in mysql, I sometimes get data from both research I come across the typical "link two tables", "make two queries to two tables", but this has me confused.
That is, if we have two tables, as follows:
Tabla1
| id | nick |
|-------------
| 1 | admin|
tabla2
| id_post | content | autor |
|---------------------------------
| 100 | asdasd | 1 |
Why relate from mysql, but when you query you can do:
select tabla1.nick, tabla2.* from tabla1, tabla2, where id="1" and tabla2.autor = tabla1.id
What is the difference between the two?, Or what is the benefit to having one or the other?
If I understand your question correctly, you're asking about constraints, why actually make column X on table A refer to column Y on table B, when you can just join the two tables in a SELECT query?
This is to enforce referential integrity, to reduce redundancy, etc. Doing so makes the data itself reliable so that when you use joins in your SELECT statement, they work as they should.
If you had an ASSIGNMENTS and a SUPERVISORS table, for instance, and each assignment is always assigned to a supervisor on a supervisors table, a foreign key constraint between the supervisor field on ASSIGNMENTS and SUPERVISORS will ensure that happens. It also gives you flexibility as to what should occur if the supervisor value changes on one table (should it be restricted? should the change be carried through to the other table? etc.)
Without the relationship being defined, an assignment might be assigned to a supervisor who does not even exist. And then the results of your SELECT statements won't be all that reliable...
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 9 years ago.
Improve this question
Hi I am new to web technology (Well not advanced). I am trying to build an online store (computer hardware) with mysql and PHP, I am wondering how to add a search functionality (not google's).
I am planning to make a search bar where visitors can enter key word or key words for search.
The search for these key words should span many tables with totally different content.
I know about SQL syntax, I have a good understanding of REGEXPs, I am good with indexes and views...
The only thing I want is guidance, a general idea.
you should first design your database. then make website design and program it in PHP.
as far as search functionality concerns you should make something like that,
eg.
database and tables and their columns etc..
for example, if you have one table named hardwares
+--id---+---Name----+---Cost----+-Warrenty--+
+-------+-----------+-----------+-----------+
| 1 |hardware1 | 2000 | 2 |
| 2 |hardware2 | 5000 | 1 |
| 3 |hardware3 | 5000 | 3 |
+-------+-----------+-----------+-----------+
then in coding part of the website there will be query fired something like that,
select * from hardwares where Name LIKE '%$search_input%`
here, the search input is taken from the user and this query will result the particular hardwares' information and then from the results you can get ID of that hardware which is already stored in that table.
from that ID, you can make a page that will accessed by a particular query for example,
http://www.yourwebsite.com/hardwares.php?id=2
this page will load that particular hardwares' page and it will have all the information regarding to that hardware.
Search from catalog items - this is search for database.
MySQL code
SELECT nameItem FROM catalogItem WHERE `nameItem` LIKE '%search phrase%' OR `descriptionItem` LIKE '%search phrase%'
This is the simplest example.
A architecture of search I would do with caching results in a separate table.
PS See how to implement search in popular CMS
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want a simple non-MySQL PHP script that allows viewers to vote up or vote down a page. If it has to be MySQL database driven, then that's just how it has to be. Ideally, not though.
So basically if you were to view source of this page in a web browser it would look something like this:
<h2>Stack Overflow Is Cool</h2>
<span id="author-info-etc">Written by Ben Dover on 01-01-2012 (+12) | (-3) Total Rank: +9</span>
<p>Once upon a time there was this really cool website called Stack Overflow where amazing people would help answer questions asked by people who destroyed their keyboards by throwing them against their computer screen in an act of utter frustration and despair.</p>
And the source file would look like this:
<span id="author-info-etc">Written by <?php echo $authorname; ?> on <?php echo $pubDate; ?> <?php include ('pagevotescript.php'); ?></span>
Could someone help me to create this PHP script?
If you're wanting to have a reliable voting system, you'll need to use a database such as MySQL to store votes in. Otherwise, how will your web app know how many votes a page has received?
Your database structure could look something like this:
Pages
page_id | page_name
-------------------
1 | My Page
2 | Test
Users
user_id | user_name
-------------------
1 | John
2 | Sara
3 | Tom
Votes
vote_id | user_id | page_id | vote_weight
-----------------------------------------
1 | 1 | 1 | 1
2 | 1 | 2 | -1
3 | 2 | 2 | 1
4 | 3 | 1 | 1
When a user votes:
Check to see if they've already voted on the page.
If so, either deny them another vote or update their existing vote.
If they haven't voted on the page in question, insert a new vote.
It would be easiest to store page data in MySQL and just have a column called votes. This way you would display the page and pull in the votes at the same time, and could easily up/down the votes when the user interacts.
Without MySQL, you would need to store the value in a file somewhere. You could have about-us.php and then about-us.php.txt where the txt file would be a simple # that could be retrieved and then changed and reset. Something like this:
// Open file for reading and writing
$fp = fopen('about-us.php.txt', 'w+');
//Retrieve contents of file as integar
$count = (int) fread($fp, filesize('about-us.php.txt'));
// Take the count and up it by 1
$count++;
// Write the changes
fwrite($fp, $count);
// Close the file
fclose($fp);
You need a way to persist your data between sessions, so you need a database, if you don't want to install mysql, I think last versions of PHP come with sqlite built-in support.
You want to have a database with users and posts. Users should be able to vote up posts, increasing or decreasing the 'reputation' count of a user. To store all this information, you are already going to need a database.
If you still want to store the 'vote' information in something else then a mysql database, there are plenty of options. text file, NoSQL, Couchdb and many other options.
It is going to be much easier for you to learn how to communicate with a database then doing something like storing the info in a file. And since mysql is the most common used database, it would be a rather intelligent choice.
PS: If you are starting to learn mysql, you should definately not start using the PHP mysql_ functions, but rather something like PDO, to circumenvent SQL-Injections.
The low-tech approach is to use a key-value store with PHP to store your values. An example is the dba_* functions within PHP like dba_open which creates a single-file database that behaves like any regular file, no server required.
Example:
$db = dba_open("stats", "r", "gdbm");
$count = dba_fetch("/page/path", $db);
dba_insert("/page/path", $count + 1, $db);
As a note this would be subject to subtle race conditions where two or more simultaneous requests would fetch and save the same incremented value. Using a proper database, even the embedded SQLite, would be a better idea.