php or mysql question

This is a discussion on php or mysql question within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'm not sure how to do this so I don't know if I would do it with PHP ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-20-2004
Jason Cooke
 
Posts: n/a
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


Reply With Quote
  #2 (permalink)  
Old 01-20-2004
Jedi121
 
Posts: n/a
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
?>


Reply With Quote
  #3 (permalink)  
Old 01-20-2004
Tom Thackrey
 
Posts: n/a
Default Re: php or mysql question


On 20-Jan-2004, "Jason Cooke" <jc@jcimedia_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
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0