问题
I am very new to PHP and am trying to find the best solution to my problem. In my database I have a field "painters". Within painters I have "painter A", "Painter B",and "Painter C". Is their a way to display painter c if certain art work comes up? Or Painter "B", if a certain art work comes up? I am trying to understand the best way to do something like this dynamically. Any links, code, or tutorials would help me tremendously! Thanks so much in advance!
-Mike
回答1:
You are going to want 3 tables. A "Painters" table, a "assoc" table, and a "Painting" table.
Painters table includes:
- ID
- Name
- DOB
- Phone
- Address
- Blah
- blah
Painting table includes:
- ID
- Name
- Date_Created
- Blah
- Blah
- Blah
Assoc table links them... It looks like:
- ID
- PAINTER_ID
- PAINTING_ID
So you can say SELECT PAINTING_ID FROM 'ASSOC' WHERE PAINTER_ID = '$Your_variable' Then with that result set iterate through that array with a foreach.
Inside that foreach: you will
SELECT * FROM PAINTINGS WHERE ID = Array['PAINTING_ID'].
That's a basic associative relational database.
You can google more about it, but that's the basics that should get you started
回答2:
Start by reading these W3 tutorials.
http://www.w3schools.com/php/php_mysql_connect.asp
If you are like me and you need a visual aid then watch this tutorial, without this guy I wouldn't know anything about PHP, and I wouldn't have been able to creat my own CMS software, which I use for many of my clients.
For some reason the link won't post so Google "build a cms php youtube" and then click on the first video result :)
In future, it is good to try it yourself, and when you stumble upon problems, post on Stack Overflow, your question was a little to vague here.
来源:https://stackoverflow.com/questions/11585964/php-database-call