Jul 25, 2008

Dynamically Select From 2 Tables Based On Id - dynamically select from 2 tables based on id

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Dynamically Select From 2 Tables Based On Id - dynamically select from 2 tables based on id

eskimmer
hi there,

im working on a performance request system, and i have three tables that im working with right now. the performances table holds the info about the performance (date, times, status, etc.), and has two columns, org_type and org_id, which both hold an int value to tell me where the organization info is. there are two org types which have respective tables, because we collect different information based on the type of org that is registering. is there any way to select info from all three tables (dynamically selecting between the two org tables based on org_type, then selecting the proper org info based on org_id) in one query?

what im using:
mysql 5.0, MyISAM tables
php 5.2

Reply

Stenno
Yes there is away to select info from mutiple tables out your database. This is the way:

CODE
SELECT p.date, p.time, o.name, o.blabla FROM `preformance` AS p AND `organization` AS o WHERE o.id = p.org_id;


or

CODE
SELECT preformance.date, preformance.time, organization.name, organization.blabla FROM `preformance` AND `organization` WHERE organization.id = preformance.org_id;


But as you can see the first method is way more efficient. Good luck with it

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : dynamically tables based id dynamically tables based id

  1. Sending E-mails Based On Intervals? - (7)
  2. Remove A Value From A Php Array Based On Its Value - (5)
    I have an index array CODE $array[0] = 10; $array[1] = 12; ...
    Its kinda late and I'm falling asleep now but I had a quick look through PHP.net, and could not
    find what I'm after, Maybe I'm too sleepy, sorry, but if anyone knows off the top of their
    head a way to removed members in that array based on its value, i.e. I wanna remove values 12. I
    don't really want to do a loop but if I cant find any existing function to do it, then I may
    have to. Thanks for any help....
  3. Creating Something With Co-ordinates With Php. - Something like you see in those web-based php games, like a map or som (12)
    Well, i was just wondering if something simple and basic could be made (like a small map where you
    could move around on, like you click up, and your position moves up and reports it to the
    database..etc) with co-ordinates in php . Taking the x-axis and the y-axis into consideration.
    Things like maps which online games have such as web-based space games or legacy-game.net. Thanks
    for any feedback, ~Aldo...
  4. Looking For Command Line Based Sql Modification - Program Needed For SQL? (1)
    How I use Windows command prompt client and do modifications to my SQL database. If yes, please
    write the commads I should know for that. If no, please get me the software with which I can do it.
    Topic title modified. Proper English is always required when posting in our forum. ...
  5. Php And Irc - PHP-based IRC web client (5)
    I am wondering whether or not you could create a basic client for IRC using PHP. I know that PHP
    does have IRC functions which I read about on php.net. I am not quite sure whether or not a client
    could be built around this. I do know that there is a CGI IRC client on the web. I use this while I
    am on my Wii I am wanting to incorporate a PHP IRC client into my website and use AJAX to
    automatically reload the chat. Well, if anybody could help that would be great....
  6. Compare 2 List Of User Ids From Different Tables - (1)
    Hi all. I am trying to make a list out of 2 list. The first list is a complete list of users id
    from users table (List A) The Second list is of users id from another table (List /cool.gif"
    style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> I want to subtrack the user
    ids in List B from List A and make List C. Thanks in advance for any help /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Update: I looked up a old
    sql book i had and found some query examples. I tried the EXCEPT statement in mysql but it dont wor...
  7. Storing Session Variables Generated Dynamically - (3)
    i have many pool (quiz) modules on my site with the information taken from a database. The modules
    are processed by the same function with different parameters and i need to save the pool's
    status to prevent a user vote several times. I do this setting $_SESSION to 1 , variable
    being the name of the quiz, which is taken from the database. So i get to having a code like this:
    .................... $name= $row->quiz_name; $_SESSION =1 The problem is that if
    i call $_SESSION from another part of the site (another page) the variable is al...
  8. Creatin Tables In Mysql - (4)
    Hi everyone!
    I have a problem: when I create a table in MySQL,
    I'm asked to fill up some information about each colum.

    for example:
    | Name | Type | Value | 2nd Value | Attib...
  9. Problem To Join Tables In Database - Problem in joining (many to many) relation (3)
    Please help me. I'm building a group of database fro a program. the situation is like this:
    'user' may have 1 or more class(es). 'class' itself may have 1 or more user in its
    classroom. I'm bad at explaining... maybe like this: A program is made to write data of
    classroom. Hikaru has a math class at Monday and statistic class at Tuesday. The math class itself
    consists of about 50 students in a classroom. So, Hikaru (user ) may have one or more class at
    time, math class (class) may have one or more students at time. So, basically I must mak...
  10. An Sql Problem In Php - returnin the name of the tables (1)
    hello again guys!, i was wondering if there is a way to get the table names from my database
    using php. Well what i want to do is to get the name of the tables returned as an array or something
    similar... thanx in advance...



Looking for dynamically, select, 2, tables, based, id, dynamically, select, 2, tables, based, id

Searching Video's for dynamically, select, 2, tables, based, id, dynamically, select, 2, tables, based, id
advertisement



Dynamically Select From 2 Tables Based On Id - dynamically select from 2 tables based on id



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE