Forum Moderators: coopster

Message Too Old, No Replies

opinion please

         

bodycount

2:08 pm on Jun 9, 2006 (gmt 0)

10+ Year Member



Is this the best way of creating and drop down list getting data from a few tables or is there a better way.

<?php
$query1 = "(SELECT DESCRIPTION from oemmodem56c2)
UNION
(SELECT DESCRIPTION from fg000092)
UNION
(SELECT DESCRIPTION from fg000071)
UNION
(SELECT DESCRIPTION from gprs0007)
UNION
(SELECT DESCRIPTION from gprs0003)
UNION
(SELECT DESCRIPTION from carrierboard)
UNION
(SELECT DESCRIPTION from boxproduct)
UNION
(SELECT DESCRIPTION from fr06000104)";
$result1 = mysql_query($query1);
$num_rows=mysql_num_rows($result1);
while ($row=mysql_fetch_array($result1))
{
$DESCRIPTION = $row["DESCRIPTION"];
echo "<option value=\"$DESCRIPTION\">$DESCRIPTION</option>";
}
echo "</select><br>";
?>

coopster

2:19 pm on Jun 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A UNION will typically be the fastest query, but why do you have all the descriptions in multiple tables? The bigger question is, once a description is selected, how are you going to know which table to query next? Or don't you need to?

bodycount

2:43 pm on Jun 9, 2006 (gmt 0)

10+ Year Member



The bigger question is, once a description is selected, how are you going to know which table to query next? Or don't you need to?

Once a description is selected then another page loads up containing the right input fields for that product.

why do you have all the descriptions in multiple tables?

I have mulitple products with differant descriptions, I have created and new table for each product.

I have never created a db before so maybe mulitple tables is not the best way to do it. Any pointers would not go a miss.

coopster

2:54 pm on Jun 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You likely won't want to create a new table for each product. I'm guessing that you are probably finding yourself copying the same table each time, more or less, correct? Each product has an identifier, a description, price, etc. They are more or less the same every time. So, you probably want a single products table and use that to store all your products and associated information. There is even a term for it in the database world, normalization.

Once all the products are stored in a single table, now all you have to do is query one table as opposed to all those UNION SELECTions. Make sense?

bodycount

3:17 pm on Jun 9, 2006 (gmt 0)

10+ Year Member



Yep your right 99% of the date fields are the same.

I will change to just one product table and get rid of those UNIONS

Lucky for me no/not much data has been inputted so i can change it.

Thanks for all your help

coopster

3:45 pm on Jun 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



No problem. Also, some spare-time reading for you ;)
I remembered seeing a thread once regarding Normalization - A Brief Introduction [webmasterworld.com]. And here are a couple others:
[webmasterworld.com...]
[webmasterworld.com...]

bodycount

10:17 am on Jun 12, 2006 (gmt 0)

10+ Year Member



Thanks for your help ,and the links. I will put this into practice straight away.