SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    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

  2. #2
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Olean NY
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone? =(

  3. #3
    SitePoint Member
    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?

  4. #4
    SitePoint Addict
    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

  5. #5
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Olean NY
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Itshim
    Are you getting an error back from the database, or is the query simply not returning the correct results?

    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.)

  6. #6
    SitePoint Addict
    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();
    right after "$statsqlr=mysql_query($statsql);" this will print the error returned from mysql to the page and may help in finding the error with the query.

    I am surfing the MySQL documentation right now looking for help in query between to different DBs for some information.

    Thanks,
    Itshim

  7. #7
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Olean NY
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Itshim
    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();
    right after "$statsqlr=mysql_query($statsql);" this will print the error returned from mysql to the page and may help in finding the error with the query.

    I am surfing the MySQL documentation right now looking for help in query between to different DBs for some information.

    Thanks,
    Itshim
    I'll try that right now, but it's between two "tables", not two Dbs. :P

  8. #8
    SitePoint Member
    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.

  9. #9
    SitePoint Addict
    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.

  10. #10
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Olean NY
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Itshim
    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.
    Well that's what Im not sure of, how I can draw something from teams, and then draw something from the ladder_# using information already DRAWN from teams... in one query.

    Maybe it's not possible.

  11. #11
    SitePoint Addict
    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.

  12. #12
    SitePoint Addict
    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.

  13. #13
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Olean NY
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Itshim
    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.

    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.

  14. #14
    SitePoint Addict
    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

Posting Permissions

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