Professional Web Applications Themes

php or mysql question - PHP Development

I'm not sure how to do this so I don't know if I would do it with PHP or if I can actually do it in a SQL statement but heres the scenario. I have 5 tables that I'm retrieving data from. The main table houses an "ownerID" which is a number. Then number and associated owner are in a table called owners. When I pull the results from the tables I of course get the number of the owner. I would like to fill that in with the name of the owner upon display. Can I modify my sql ...

  1. #1

    Default php or mysql question

    I'm not sure how to do this so I don't know if I would do it with PHP or if
    I can actually do it in a SQL statement but heres the scenario. I have 5
    tables that I'm retrieving data from. The main table houses an "ownerID"
    which is a number. Then number and associated owner are in a table called
    owners. When I pull the results from the tables I of course get the number
    of the owner. I would like to fill that in with the name of the owner upon
    display. Can I modify my sql statement to take care of the association or do
    I do it in PHP. Here is my current sql statement. Any help would be greatly
    appreciated. Thank you

    -------start sql-------

    SELECT inventory.productID, inventory.price, inventory.ownerID,
    minerals.speciesID, minerals.`size`
    FROM inventory, minerals
    WHERE minerals.productID = inventory.productID
    AND inventory.productType = 'm'

    -------end sql-------

    Jason


    Jason Cooke Guest

  2. #2

    Default Re: php or mysql question

    Jason Cooke a écrit le 20/01/2004 :
    > I'm not sure how to do this so I don't know if I would do it with PHP or if
    > I can actually do it in a SQL statement but heres the scenario. I have 5
    > tables that I'm retrieving data from. The main table houses an "ownerID"
    > which is a number. Then number and associated owner are in a table called
    > owners. When I pull the results from the tables I of course get the number
    > of the owner. I would like to fill that in with the name of the owner upon
    > display. Can I modify my sql statement to take care of the association or do
    Yes you can
    > I do it in PHP. Here is my current sql statement. Any help would be greatly
    You can also do it in another query if it is what you meant by "do it
    in PHP". It depends if you have a lot of rows returned by your first
    query and if you'll need other other info of your "owner". Otherwise
    you can use jointure to do the trick.
    I think in your case I would choose to have a separate SQL query to
    retreive all owners details. Something like
    <?php
    //considering $myVar contains the ownerID returned by your SQL command
    $sql = "SELECT * FROM owner_table WHERE ownerID=$myVar";
    //code to treat the SQL command
    ?>


    Jedi121 Guest

  3. #3

    Default Re: php or mysql question


    On 20-Jan-2004, "Jason Cooke" <jcjcimedia_JunK_.com> wrote:
    > I'm not sure how to do this so I don't know if I would do it with PHP or
    > if
    > I can actually do it in a SQL statement but heres the scenario. I have 5
    > tables that I'm retrieving data from. The main table houses an "ownerID"
    > which is a number. Then number and associated owner are in a table called
    > owners. When I pull the results from the tables I of course get the number
    > of the owner. I would like to fill that in with the name of the owner upon
    > display. Can I modify my sql statement to take care of the association or
    > do
    > I do it in PHP. Here is my current sql statement. Any help would be
    > greatly
    > appreciated. Thank you
    >
    > -------start sql-------
    >
    > SELECT inventory.productID, inventory.price, inventory.ownerID,
    > minerals.speciesID, minerals.`size`
    > FROM inventory, minerals
    > WHERE minerals.productID = inventory.productID
    > AND inventory.productType = 'm'
    >
    > -------end sql-------
    That's what relational DBs are all about.

    SELECT inventory.productID, inventory.price, inventory.ownerID,
    minerals.speciesID, minerals.`size`, owner.name
    FROM inventory, minerals, owner
    WHERE minerals.productID = inventory.productID
    AND inventory.ownerID=owner.ownerID
    AND inventory.productType = 'm'

    BTW you don't need the backticks around size, it's not a reserved word

    --
    Tom Thackrey
    [url]www.creative-light.com[/url]
    tom (at) creative (dash) light (dot) com
    do NOT send email to [email]jamesbutlerwillglen.net[/email] (it's reserved for spammers)
    Tom Thackrey Guest

Similar Threads

  1. dbi::mysql question
    By rob merritt in forum PERL Beginners
    Replies: 0
    Last Post: January 2nd, 06:53 PM
  2. More of a mysql question
    By hokieghal99 in forum PHP Development
    Replies: 1
    Last Post: October 27th, 02:43 PM
  3. Question regarding PHP and mySQL
    By Me@lost_pls_help in forum PHP Development
    Replies: 1
    Last Post: July 27th, 09:57 PM
  4. PHP + MYSQL Question!
    By R.Lange in forum PHP Development
    Replies: 2
    Last Post: July 20th, 01:03 PM
  5. A MySQL question
    By Zavaboy in forum PHP Development
    Replies: 5
    Last Post: July 14th, 11:26 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139