SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mixing tables on a page

    Hi...It's me again

    I've got a page setup to show everyone profile. Things like Rank, Name, Pionts, etc.

    This may not be the best way to go about it, but i'm a newbie to coding & databases.

    I'm wondering, if I want to add a html table to the area under this info to show each players awards would I need to add columns in the db table holding the rest of their info or do I setup a new db table & put the info in there? This information would include:

    1.) The image
    (need your openions on this one, do I store the image in a folder or should I store it in the db? There are about 25 different medals.)

    2.) Description of the medal (What it's for)

    3.) Times it was won. ie: You can get unlimited number of "Armageddon Awards."
    You smell something?

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    None
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It really doesn't matter - add columns to the existing table or store data in a separate table. I would store it in a separate table (personal preference).

    I wouldn't store Images in the database, I'd store them in a folder and just place a link or an image tag into the database to display that image.

  3. #3
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well then that leads to new questions for me.

    1.) What do I put in the field to represent the image in the database? Could I just put something like

    <img src="images/arma1.gif" width="16" height="14">

    or do I need to put the full path? Or is that even going to work? lol

    2.) When I create the new table to hold the medals info How do I relate that info to who has them & who doesn't?
    You smell something?

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you'd store the url in the table, and when you wanna pull it from the database do this:
    PHP Code:
    <img src="<? echo $row[your_image]; ?>
    this is of course assuming that your query above pulled the info in a manner like this:
    PHP Code:
    $sql "SELECT * from your_table";
    $user_results mysql_db_query($db_name$get_users$db_connect);
    $row mysql_fetch_array($user_results); 
    some notes on the php up there.

    $sql's query is to pull the entire table's contents for your use.
    now, everything in the table (each column) will be stored in $row as an array for you to pull.
    so, if you had id, name, image, and rank as column names, $row[id], $row[name], $row[image], and $row[rank] would now be available for you to use.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool thanks I think I'm starting to catch on now.

    Here's a new question though.

    The same medals are available in three different "classes" displayed on the page.

    First class

    Second class

    and Third class

    All can contain the same awards but they must read correctly.

    For instance. if you had 2 "Armageddon Awards" that were first class awards. you might have 12 "Armageddon Awards" in second class or third class.

    To give you an example of what i'm doing look at this pageas an example.
    You smell something?

  6. #6
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what's your question?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  7. #7
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I make sure it shows the correct number of times the award was won in the correct class. ex:

    player has 2 "Armageddon Awards" in first class

    and 3 "Armageddon Awards" in second class.

    How do I make sure it doesn't say the award was won 2 times in first class & 2 times in second class? or 3 times in both classes?

    It may just be my newbie way of explaining.

    I'm trying to figure out right now how to put the data into the database.

    Should I:
    A) Make 3 tables with the same info calling the tables medals1, table 2 would be medals2, & table 3 would be medals3.

    b) Make 1 table called medals and put the info in there? <= this one im doing now

    And what fields should I use to put them into the db? Right now i've got 3 columns
    image, description, num

    Right now i'm not using num because I relized I shouldn't be storing the number of times it's won in there.

    Which brings a new question, do I need to add columns in the table player_profile to hold these values?

    the table player_profile hold the other info currently in their profile like their name, rank, location, etc.
    You smell something?

  8. #8
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe this will help?

    What I'm trying to accomplish is having ONLY awards they've won appear in the appropriate hmtl table With the number of times they've recieved the award. If they have not won any awards, like when the first become a member, then nothing appears in the html table where their awards belong. Get it?

    I think what i'm basically looking for is how to make the db understand what awards, and how many, belong to who.
    You smell something?

  9. #9
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, you could have 2 seperate tables.
    i'm assuming you have a sort of users table with all the user info.
    make a table called awards and have a seperate column for each different award.
    then have the primary key for that table be the userid from the user table.
    perform a join on these tables then when you call your sql to grab the info just have it do something like SELECT * from awards WHERE userid = 'his_id'
    then using the example above (where $row is used) you could do
    PHP Code:
    if($row[award1] > 0){
    echo 
    "<td>This user has $row[award1] of award 1</td>"; } 
    etc...
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  10. #10
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh btw, when you make the awards table make sure all the fields (cept userid) have a default of 0.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  11. #11
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I think i'm following you.

    My current player information is kept in a table called player_profile, I made a new table called medals (instead of awards, I don't know why lol )

    Now in the table player_profile the only settings I have are "unique" placed on playername.

    I didn't setup any column for player_id. (Should I do this? will it make things easier on me?)

    When I make my call to get player information I have it
    SELECT from player_profile WHERE playername='$playername'

    The '$playername' variable is passed through the url that's how I get it.

    So instead of Player_id could I just use playername in both tables?

    And if I do that I would need to add the playername to both tables "player_profile" & "medals" at the same time when they sign-up right?

    BTW How will I seperate the first class, second class, and third class medals? It still looks to me like this will display all the medals but won't seperate them from being first class, second class, and third class.
    Last edited by whofarted; Sep 5, 2001 at 21:29.
    You smell something?

  12. #12
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, it was always good practice to define the primary key of the table as something that could never be duplicate. so, and id number was something i always added.
    if theres no chance of every duplicating a playername, than you don't really need the id
    it's just something i find useful.

    oh and on the note of keys, don't forget to define your primary key field!
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  13. #13
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    um... ok....what about the rest of the questions in the previous post?
    You smell something?

  14. #14
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, well, i guess this is going to get fun.
    in that case, you might wanna make a seperate table for each award.
    and have 3 columns:
    the players name, the award, and it's class.
    granted, that might get complicated, so keep track of your joins.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  15. #15
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to waste your time. I think I figured out a way to do it that will be accepteble for the site. I've got one more question I'll ask in a new thread though. It's kinda off this topic.

    Thanks for your help though.
    You smell something?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •