Jump to content

PHP Explode & MySQL Queries


yarub

Recommended Posts

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... =\
Link to comment
https://forums.phpfreaks.com/topic/35601-php-explode-mysql-queries/
Share on other sites

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,5

games.id - games.game:
1 - Game Name 1
2 - Game Name 2
3 - Game Name 3
4 - Game Name 4
5 - Game Name 5

I 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.
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.
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?
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.