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
I'm making a forum where every topic can have a set of tags(like the tags on stack overflow). I'm storing each topic as a row in a table that has columns for storing timestamp, title, description, etc.
What would be the best way for storing each question's tags in the mysql database preferably using php only? Should I create a new table for each topic and store the tags on seperate rows in that table? I'm sure there are more efficient ways. Please help.
Performance is an issue. And I must also be able to retrieve all the topics that belong to a particular tag.
It might be a good idea to create a separate table just for the tags and then link it to the other one by creating a column in the new one that references the Topics' ids in the first. This way if wouldn't make the original table a mess and you can still set topics for each of the tags. Hope this helps.
In fact your shoud use two tables.
Tag - table to store tags
Topic2Tag - to store relation betwen tags and topic
so your system will get max flexibility
Or you can store tags in one column of topic table separated by comma, but if later you wil try to do something whith tags .... "this is heavy"
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 6 years ago.
Improve this question
I have a data set of searches made on a website. I have to find top searches from that data set. The problem is, i cannot think of a way to do it. The search terms are long sentences. How could i find what are users interested in? It seems to be a problem of counting and i am using php. Any suggestion would be appreciated.
You can create a table in database, which will contain columns search_phrase and counter. Each time when user will search same phrase, you'll just increase counter instead of creating new row.
You can also create a script which will take all records from this table, and find similar phrases.
You can make counter corresponding to each phrase. Suppose You have a queries in long sentence format , divide your sentence into smaller parts and identify the most meaningful word and avoid the conjuctions and other verbs. Particularly focus on Nouns. For an eg, Query is : How to Make account on stackoverflow? Possible Solutions[words] : account, stackoverflow,make. Possibly in this way you can solve it.
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 6 years ago.
Improve this question
i would like to make a Quiz Application but i have some problems and i am not too sure as to how I should approach them. I am at a fairly basic level for php so was wondering if anyone could help me?
In mysql I have a database with a "Questions" table and "Answers" table.
The layout of my database on mysql
My database contains 20 question with each of them having 4 possible answers as can be seen in the link above.
I would therefore like to select all the questions and display them in a random order along with the multiple choice answers. I'm quite unsure of the coding to use. Through research I think I can use:
RAND() LIMIT 0,19 in order to randomise the questions.
The end of plan is to display the questions and answers in textview boxes on android studio. The user interface design is as follows:
User interface
I apologise that i can not give much detail on a solution it is due to my inexperience of PHP. Any help to retrieve questions and answers from mysql database through php files would be greatly appreciated.
Thanks in advance
Not sure about php, but
1. you can create an ArrayList and generate a random number in a range of your total question's id, //if you have 10 questions then 1-10
If that id isn't in the array, add it, and get the question from your question table according to the id that you've just generated
And also get your answer from the answer table and put it in another array, and then generate other three random numbers for your answers and put in the second array.
then generate number from 0 to 3 and for the second array to put the answers in 4 option(TextViews), you might wanna use a switch case approach here. (must be unique, only for each question, you can regenerate the same answers for other questions too)
if the users clicks/chooses any of them check with the answer and there you go
6.
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 have to create a sort of poll with random questions and I wanted to ask you whether the best way to store these random questions in my MySQL db would be
storing the questions as string, which means I would extract via PHP the random questions from the bunch I've got and save them in the database like this
storing the questions' IDs as a string (e.g. "1_2_3_4_5") and then using PHP I get an array out of it using explode() and take out of the array with the questions' texts using the IDs:
Table.
or please suggest me a better method.
Thank you really much, appreciate your support, I hope I explained it clearly and sorry for mistakes.
I'd create a table for Questions and a table for QuestionResponses, at a minimum. QuestionResponses can have a foreign key reference to Questions, along with a VARCHAR(SOMELENGTH) field for storing the response.
I would go with your first option. You can just store the questions as strings in the database, and use php/pdo to randomly select the amount of questions you want per time in an array, then print out the array content randomly. (English is hard sometimes, so i'll explain again)...
Say you want to produce 5 random questions per user that tries to use the application, you can have at least 50 questions in the database stored as string, then "randomly" select 10 questions from the database (this is to avoid selecting all the questions every time or selecting the same set of questions), from the 10 randomly selected questions (which is now in an array), you can randomly print out 5 for the user.
So you have two sets of randomization.
I hope this makes a little sense and helpful too.
I can explain myself better if you have any more questions.
Thank you.
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 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 new to PHP and have learnt it through online tutorials. I am am developing my own business website. I am looking for some guidance related to making dynamic web pages. It's something like, if Db contents are like Continent>North America>USA>States>Area>City and other geography. My question is, do I have to create different tables for each content or can it be in single Table? Moreover auto generate customer id/property id is that the same what we chose in table rows. I am sorry for my stupid question.
My confusion is that if someone searches for example USA, it gonna appear as many timesas in columns where I had to use it for subordinate area or cities.
Each table is a set of several peices of information. For each peice of information, you create a new row inside that table. You do not need a seperate table for each peice of information, however if you need a different layout for this information, you then create a new table.
I hope this helps :)
EDIT As requested by your comment, one thing you could do would be have a column named 'region' or something in the table, and in there you could insert information such as GB>SCO
I would create one table for customers with autoincrementing id, and another table for purchases where each new purchase gets the customers id. like purchases.customerId
Then you can create a view where you link customers.id and purchases.customerId For example.
If you want a very nice youtube tutorial series about mysql, u really should look at this http://thenewboston.org/list.php?cat=49