yarub Posted January 25, 2007 Share Posted January 25, 2007 Did a little bit of searching first, but I can't find anything that's helping me. I have two databases, one for the user and one for games they play. In the user table, they're saved as 1,2,3,4,5 in that particular field. Then in the games table, it shows the name of the game that corresponds with that id from the user table.My question: how can I take that from the user table, break them up, match them up with the other table, and display what games they play? I've been playing with this for days now and it's getting rather old.Help would be appreciated it. If someone can put together a small example for me, that'd be so awesome and helpful. And please don't just link me to http://us2.php.net/manual/en/function.explode.php because that didn't help from the last people who tried to help me. I work best with examples... =\ Quote Link to comment Share on other sites More sharing options...
trq Posted January 25, 2007 Share Posted January 25, 2007 PHP's explode has nothing to do with this. You can do it in your sql query. An example....[code]SELECT users.uname AS user, games.game AS gamename FROM users,games WHERE users.id = games.userid;[/code] Quote Link to comment Share on other sites More sharing options...
yarub Posted January 25, 2007 Author Share Posted January 25, 2007 Bah- I wasn't clear on the last part of it. When I said "then in the games table, it shows the name of the game that corresponds with that id from the user table", I meant of the IDs of the games within the user table. Here are the two tables and how the relavent fields are shown.user.games:1,2,3,4,5games.id - games.game:1 - Game Name 12 - Game Name 23 - Game Name 34 - Game Name 45 - Game Name 5I want to be able to make an area of the site where I can list out what games they play. Rather than printing out "1,2,3,4,5" I want to print out "Game Name 1, Game Name 2, Game Name 3, Game Name 4, Game Name 5" or something like that. Quote Link to comment Share on other sites More sharing options...
trq Posted January 25, 2007 Share Posted January 25, 2007 Surely you can see what my example does? How about you attempt to write the query yourself and post it if you have problems. Quote Link to comment Share on other sites More sharing options...
yarub Posted January 25, 2007 Author Share Posted January 25, 2007 If I could, I would, but I don't understand how I'd do it the way I want to.If I would pull out "1,2,3,4,5" from the field, how would I split those up and change them into the names? The query that you wrote... and anything I've previously learned plus what you showed me would still result in me not knowing. ._. I'm far from a guru. Quote Link to comment Share on other sites More sharing options...
trq Posted January 25, 2007 Share Posted January 25, 2007 Are you actually saying you have stored a string in the users table ("1,2,3,4,5") to relate users to a game? Sorry, this is a pretty poor design choice, and yes, Ive misread your question.For this, your going to need to let PHP do some work. One question.... this list of username / games they play... do you want it to list each user and the games they play, or just one user at a time? Quote Link to comment Share on other sites More sharing options...
yarub Posted January 25, 2007 Author Share Posted January 25, 2007 I was trying to mimic the way vBulletin does it for storing usergroups. It was just harder than I thought. =\Well, here are the two things I want to do. I have a member list page that I want to be able to let the viewer select a game and show all the people who play; a drop down list or something. Then when they go to a member's profile, it actually lists all of the games the play.If you believe there is an easier way to do this, let me know. I was just trying to get away from having 50 tables for each game, or having to alter a table to add or remove games. Quote Link to comment Share on other sites More sharing options...
trq Posted January 25, 2007 Share Posted January 25, 2007 Look up some tutorials on database normalization, should make it much more efficient. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.