Best way to select id's from seperate mysql table??

Discussion in 'PHP' started by lui2603, Jun 4, 2008.

  1. #1
    Think of this as a map appication I am writing...
    I have 2 tables in my database (tiles and tile_positions)

    An example of what the fields look like:
    
    TILES
    ============
    tileID: 1
    tileIMG: something.jpg
    ============
    
    TILE_POSITIONS
    ============
    ID: 1
    tileID: 1
    xpos: 0
    ypos: 0
    ============
    
    Code (markup):
    Here is how I would retrieve the images and positions for the tiles.
    
    while($tile = mysql_fetch_array($posquery)){
    $imgquery = mysql_query("SELECT * FROM tiles WHERE tileID='$tile[tileID]'");
    $img = mysql_fetch_array($iquery);
    echo '<img src="'.$img[img].'" />;
    }
    
    PHP:
    Is doing a seperate mysql_query for each tile going to be overkill for mysql if there are 50-ish tiles with different ID's for each page?

    If yes how would you recommend doing it?
     
    lui2603, Jun 4, 2008 IP
  2. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #2
    hello,

    try this query:

    
    SELECT tiles.tileID, tiles.tileIMG, tile_positions.tileID, tile_positions.xpos, tile_positions.ypos FROM tiles, tile_positions WHERE tiles.tileID = tile_positions.tileID;
    
    Code (markup):
    Let me know if it works or not.
     
    mehmetm, Jun 4, 2008 IP
    lui2603 likes this.
  3. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah after a few changes to get it to select 50 more it works great, thanks!
    Rep added! :D
     
    lui2603, Jun 4, 2008 IP
  4. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4
    your welcome dude, actually itrade is preferred :D
     
    mehmetm, Jun 4, 2008 IP