Advice on managing this database - php

its my first post here and im a bit worried about if it fits this forum.
Im making a project about a music library online, you signup in the website and you can add songs to your own list, something similar to spotify maybe. But i have some doubts about inserting the songs in the database because i dont want to have a popular song 30 times in the database, one idea i had is to only allow to insert songs in the database to an "admin" and people can see that admin song's list and add from there to their list and if the song you want is not in the list contact the admin but that seems tiring for the user. I guess another good option is that the form to add a song to your list shows you a select where you see existings album/songs and if you cant find it there then you create it in the database, but i need to think more into how to perform that idea.
The database is created with mysql, im pretty sure i will use pdo
database design

Finally i think is a better idea to connect library table with song instead of album so people can have couple songs instead of the whole album and im going to manage the inserts from the website with selects on the form so the user doesnt create already existing content, sorry for the post to that people downvoted it

The other idea you mentioned is a good option.
Say you have three dropdowns one of Artist, second of Album and third of songs. Here you can list all the Artists in the database in the first dropdown. On selecting an artist, the albums related to the artist selected can be populated in the second dropdown. On selecting an album from this dropdown can populate all the songs in that album in the third dropdown. If the user feels that the song he wishes to add is not available in the third dropdown, he can click a button saying 'Suggest an Addition'. Clicking this button, a popup will appear which will have a dropdown of Artists available in the database, and another dropdown of all the albums. Against this selection, he can add a song.
Also, I would suggest that every newly added song be subject to admin approval. This will prevent the duplicate entries of songs. For this, you can have a flag in the songs table which will be set based on admin approving the newly added song.
example:
Select Artist (dropdown 1)
Select Album (dropdown 2)
Select Song (dropdown 3)
Suggest an Addition (button)

Related

Dependent Drop down in Grocery CRUD (CodeIgniter)

I stucked in a Problem When Playing with Drop Downs.I tried to use this
http://www.grocerycrud.com/forums/topic/1087-updated-24112012-dependent-dropdown-library/
But actually my requirement is quite different. I have a table fwld_products in which i am adding all other table's categories, from
fwld_cat_main (main Category's ID),
fwld_cat_sub1 (sub1 Category's id)
fwld_cat_sub2 (sub2 Category's id)
fwld_cat_sub3 (sub3 Category's id)
I want to Display Dropdown in such a way, when user Selects main
Category, the Drop Down Appear (sub1) Having Data related to main
category and when sub1 selected drop down appear (sub2) showing data
related to sub1, and sub2 selected and drop down appear(sub3) to show
data related to Drop down (sub2).
When submitted Finnally data inserted to [fwld_products].
Here I am attaching ERD, and result as well.
Please help
Hold on, it seems that DB structure of your categories table needs to be improved. What I suggest is that you follow footprints from some of the popular CMS like Opencart. It will give you a great sense to accomplish your task. You can easily optimize your DB by using just one "category" table (instead of main, sub1, sub2, and sub3 category tables) like this:
For category names, description, and meta keywords etc you can create this table "category_description":
Finally to assign categories to the products you can simply create another table "product_to_category":
In this way you can easily manage your data in DB and you can now easily tackle your situation using Codeigniter and Grocerycrud.
Try, Chained Selects Plugin for jQuery and Zepto (Github Project | Project Home)
If you use jquery or zepto in your project, this plugin will help you to solve your problem, Specially the remote version. You can create related select boxes easily.
Hope this helps :)

MYSQL table suggestions

I am new to MySQL and PHP. I am having issues wrapping my mind around how to accomplish something. I am building a site that has basically a forum style post page. Users enter text into a textarea which then posts that text along with a timestamp and $_SESSION['Username'] into a MySQL table titled "campaigns." So the table has postEntry, postName and postDate rows currently.
On this same page that I have the form, I then display the entire contents of the campaigns table into a div. So it can show each post in descending order.
This has been working great for me, but I am now trying to look at the bigger picture and am thinking this is not a good way to do what I need. I basically need the ability to have an endless amount of "campaigns" each with their own set of posts. Then give the user the ability to select which campaign they want to view and show corresponding posts for that campaign in the div.
So the real question is: Is there a way to do this with just one table. Or would each campaign need it's own table in the database?
Add a campaign_id to the POST table and viola!
edit: more info:
you need one table for the campaign like so:
Campaign
-------------
campaign_id
name
then you need another one for all the posts
post
-------------
post_id
campaign_id
post_time
name
this way, each post is associated to a specific named campaign.

Entering new/editing existing DB records with info from multiple tables

So, I have a database for a mock phone site that has been built to the spec. My database has a table called phones, a table called operatingsystem and a table called manufacturer. I need to create a form to enter a new phone into the database. The problems I have run into are:
I need to basically get the form to add a new record to the phones table. However, the phones table pulls data from other tables as well. An example of this is how I have the operating systems (iOS, Android, BlackBerry and Windows Phone) stored separately in the operatingsystem table and each have an ID assigned (1, 2, 3 and 4) as well as having the manufacturers being stored in a manufacturer table (HTC, Samsung, Apple etc.) each with an auto increment ID. I'm not sure how I'd design the form so that the user can either add a new phone to the database simply by using the form or can add a new manufacturer/OS to the database if needed. I've got to do it assuming that the user adding the phones/editing existing ones hasn't got access to the database so obviously they don't know that manufacturer ID 1 is Apple, 2 Samsung etc.
I basically need to use a combination of a HTML form and accompanying PHP page so that phones can be added, edited or deleted altogether from the database. What would I do in terms of form design and what PHP would I need to use to be able to add/edit/delete data from multiple tables?
Sorry for the long-winded post but any help would be appreciated and if any more details are needed, please do not hesitate to ask. Thank you.
For selecting the manufacturer and operating system, the <select> element is the obvious choice. It creates a drop-down with selectable options, with a potential separation between the value passed and what the user sees.
So, if you had this:
<select name="manufacturer">
<option value="1">Apple</option>
<option value="2">HTC</option>
<option value="3">Samsung</option>
</select>
then the user would see Apple, HTC and Samsung as options. If they selected Samsung, then what would actually be submitted as that parameter's value is 3 (which would correspond to the id in your table).
For a simple/quick solution, #Anthony Grist's answer would do it. But, if you are aiming to build an automatized system that can 'live' on it's own, you'd need to build a <select> from PHP with the options that already exists and allow the user to add stuffs inside this <select> through a different CRUD. The problem with this is that users would be allowed to insert iOS, iOS 5, iOS 6, iOSasdf, etc; as they wish because you wouldn't be able to block it this much. If this is the case that you'd like to go, I'd suggest you to create a table to which you would use to feed the <select> in which table you'd have the operation_system and the table_name. If a new OS is being added, you'd use PHP to create a new table for this OS and then add it's name to the said table. When users select a OS in the select option, you'd pick that table and insert the record to it.

HTML/PHP Storing values in table, saving to database and showing it later

I am new and trying to make a simple website for a project. I have to pages, add and view hobbies. User needs to be able to add 1 or more hobbies and store it in a database and to retrieve it in another page, i have listed what i plan to do below.
How do i make it such that I am able to store multiple hobbies for users in the database?
Using MySQL, HTML, PHP, Dreamweaver
Assume: User has been created, user has been logged in and all user related database coding has been done. More than 1 user exists, all users are to have a few hobbies each.
Database
User table: UserId, Username, HobbyId
Hobby table: HobbyId, HobbyName, HobbyDaysAWeek
1 user can have 0 or more Hobbies.
Add hobby page
dropdownlist (binds list of hobbies from hobby table)
textbox (for user to enter how many days a week he spends engaging in that hobby)
add button (displays value in dropdownlist and textbox in a table)
table (Hobby and daysAWeek will be shown here, with a delete icon to delete it)
submit button(saves hobby & days a week & username into database)
View hobby page
Displays user's hobby & days a week in a table.
Thanks for helping! And please provide simple and bare minimum coding as i am new!
Well, nobody posted an answer but my question was answered in the comments so..
Start by adding a 3rd table with UserId and HobbyId – Dagon
You're storing the relationship between, not a relationship. So think of it like you have two things and you want to remember that they relate. Thus, a table with two columns, one with an identifier of one part, the other with identifier (ID) of the other part. Pull them together with the data about each part, you have information. Hence, you've stored the relationship. It's like metadata, really. It's usually pretty efficient. - Jared Farrish
Thanks guys!

Displaying dynamic text based on drop down box selection

I am using Dreamweaver to create a site.
I have created my database within phpMyAdmin and have two tables set up that contain the data I wish to display on my site. (it is a football team site and the page I am editing displays player profiles).
I have set up a drop down box, which is connected to my players table in phpMyAdmin. This I have set to display surname of the player. (I've set up the recordset to retrieve all data from my "players" table)
Below that, I have another div which contains text that I want to display based on the selection on the drop down list. For example, Position, appearances, goals, assists, etc.
Position: Dynamic text to be displayed here
Appearances: Dynamic text to be displayed here
etc
(This data would come from the "players_info" table - but the two tables are connected via the player_id field which is contained in both)
What I can't seem to do is work out how to get the text to update when the user would select a player from the drop down list.
Any help would be greatly appreciated.
Thanks
James
You can do these using ajax function.
when you select a player name ,then javascript or jquery event will be called which include a php file.
This php file must contain the sql which fetch your desired player information.
when server give response, then display it your corresponding div

Categories