SitePoint Sponsor |
|
User Tag List
Results 1 to 14 of 14
Thread: Selecting from 2 DB Tables
-
Nov 24, 2004, 13:26 #1
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Selecting from 2 DB Tables
Ok, I'm currently making a mod for a ladder script. The Database works like this:
You sign up, selecting what ladder you want to join, and then all your information.
Each ladder has a different database, 'ladder_#', which holds all of the teams statistics.
The information is sent to a table named, 'teams'.
This table contains which # ladder the team is in.
How can I draw statistics from a random team? (Who's rank is greater than 0)
I tried the following:
Code:$statsql="SELECT * FROM teams,ladder_'teams.ladderid' WHERE ladder_'teams.ladderid'.rank > 0 ORDER BY rand() LIMIT 1"; $statsqlr=mysql_query($statsql); $stats=mysql_fetch_array($statsqlr);
Obviously, this didn't work.
Any suggestions?
Also, if you don't understand my explination of how the database works, please make it known so that I can attempt to explain it better.
Thanks in advance!
- Cliff
-
Nov 24, 2004, 14:24 #2
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Anyone? =(
-
Nov 24, 2004, 17:40 #3
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Darn. Anybody know where I could get help, then?
-
Nov 24, 2004, 17:47 #4
- Join Date
- Oct 2004
- Location
- Southwest US
- Posts
- 203
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Are you getting an error back from the database, or is the query simply not returning the correct results?
Itshim
-
Nov 24, 2004, 17:54 #5
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Itshim
I get the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in mysiteURL on line 163.
(Sorry, should have posted this to start with.)
-
Nov 24, 2004, 18:04 #6
- Join Date
- Oct 2004
- Location
- Southwest US
- Posts
- 203
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, I am not sure how much I can help, since I have never tried to query over two different databases (I am correct in saying two different DBs right?).
Obviously, there is problem with the syntax of the query (like you didn't already know that) if you add:
Code:echo mysql_error();
I am surfing the MySQL documentation right now looking for help in query between to different DBs for some information.
Thanks,
Itshim
-
Nov 24, 2004, 18:08 #7
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Itshim
-
Nov 24, 2004, 18:10 #8
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Aha!
Good call.
Access denied for user: 'ladder@Myipaddress' to database 'ladder_teams'.
It's trying to access the table ladder_teams, which isn't a table. I was trying to make that have ladder_ and the ladder number, which is found in teams.ladderid.
-
Nov 24, 2004, 18:11 #9
- Join Date
- Oct 2004
- Location
- Southwest US
- Posts
- 203
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You may also want to try echoing the statment your sending to mysql, you may notice something that is not appearing the way it should.
-
Nov 24, 2004, 18:13 #10
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Itshim
Maybe it's not possible.
-
Nov 24, 2004, 18:14 #11
- Join Date
- Oct 2004
- Location
- Southwest US
- Posts
- 203
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cool glad I could help. If you have any other problems let me know.
-
Nov 24, 2004, 18:19 #12
- Join Date
- Oct 2004
- Location
- Southwest US
- Posts
- 203
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you give a me an example I maybe able to help you, I re-read what your first post said, but I am still not sure exactly what you want to get from the query.
-
Nov 24, 2004, 18:20 #13
- Join Date
- Nov 2004
- Location
- Olean NY
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Itshim
Do you have AOL instant Messanger?
It'd be easier that way.
Also, here's a picture of the DB.
I need it to randomly pick a team from the 'Teams' table, and then draw that teams stats from the 'ladder_andoneofthe#'. The problem is, the only way to draw from the correct 'ladder_#' is to use the variable in the 'teams' table named, ladderid.
-
Nov 24, 2004, 19:03 #14
- Join Date
- Oct 2004
- Location
- Southwest US
- Posts
- 203
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Currently I have no IMs installed on my computer, I know I am behind the times...
Since you need to use the id in one of the table names, I think you need to split this into two queries, but you may want to check out http://dev.mysql.com/doc/mysql/en/Subqueries.html
There could be away using a subquery to accomplish your task.
Thanks,
Itshim
Bookmarks