SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    0 Post(s)
    0 Thread(s)

    Selecting a game fron game table based on it's genre


    Consider I have two tables.

    1) `games` has fields (`id`, `name`, `action`, `adventure`, `arcade`, `online`, `author`).
    2) `genre` has fields (`handle`, `name`).

    `genre` table entries are as follows

    'action', 'Action Games'
    'adventure', 'Adventure Games'
    'arcade', 'Arcade Games'
    'online', 'Online Games'

    example `games` table entries are as follows

    'D764F', 'Road Strike', 'yes', 'no', 'yes', 'no', 'cleo'
    'C372G', 'Lost Legends', 'no', 'yes', no', 'no', 'curtis'

    So I want to get the values of fields of `games` table but the fields I want are those rows under `handle`.

    I'm looking for something like the following.
    Code MySQL:
    $query = musql_query("SELECT (`genre`'s `handle` rows) FROM `games` WHERE `author`='cleo'");

    then I'll get the values through php's mysql_fetch_array. But there is another problem then...since the SELECT fields from `games` are based on the rows of `handle` fields from `genre` table I wont be able do the following would I?

    Code PHP:
    while ($rows = mysql_fetch_array($query))
     if (rows['action'] == "yes") { echo "action" }
    since I don't know what fields will be there on the SELECT (`genre`'s `handle` value).

    I'm not sure if I explained myself well, but is there a way to achieve this?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    63 Post(s)
    3 Thread(s)
    first of all, this is the mysql forum, so it's best to talk about just the SQL, not the php code

    secondly, i don't see how your tables are related

    wopuld you kindly do a SHOW CREATE TABLE for each one | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Posting Permissions

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