Forum Moderators: coopster

Message Too Old, No Replies

Looping, str replace

replacing sql results with another sql results

         

snowman304

11:55 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



I am not sure how to do what I am needing to do. I am thinking of a loop that may do the job, but not sure how to do it or what the best way really is.

Here is my problem:

I have 2 tables in my DB. One table holds Sponsor Name and there ID number. The other table holds a list of tournaments and the ID number of the Sponsor of that tournament.

Ok, here is where I get lost. I am able to pull the tournaments from the DB and list them, but since I am storing the sponsor's ID number and not the sponsor's name in the tournament table, you see the number in the list and most users will not know the sponsor based on there ID number. What I need to do is, when I pull the tournament list from the DB, when echoed, I need to replace the Sponsor's ID number with the actual sponsor's name. So.......when echoing out the tournament list, the code needs to stop echoing, call the Sponsor table to get a list of the sponsors name and id numbers, then replace the id number with the name, Then continue echoing.

I am not sure how to do this.

Any suggestions on how to do a replace? Basically, I have a list of Sponsors being pulled from the DB and a list of Tournaments from the DB. Tournaments and Sponsors are added all the time, so hard coding a switch of names won't work, as the code should be dynamic.

phparion

5:25 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



no need to overload php when you can do it with mysql itself

Tables:
_sponsors (sid,sname)
_items (item,sid)

SELECT i.item,s.sname FROM _sponsor s, item i WHERE i.sid=s.sid

this query will select sponsor name from sponsor table and other data from items table

Recommendation: google MYSQL JOINTS and study them they are very handy

snowman304

3:11 pm on Sep 16, 2007 (gmt 0)

10+ Year Member



Thanks. I have never looked into Joint MySQL. Sounds like that is what I need. Thanks again.

-Mike