Jump to content


Photo

Size Chart and List/menu


  • Please log in to reply
5 replies to this topic

#1 maziagha

maziagha
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 01 September 2006 - 09:42 AM

Hello all!

I have this webshop today that i'm using. everything works fine until i decided that want my customers to be able to chose size and colors of the products. Now the problem is every products can have diferent sizes and colors compared to others.

My question is how can i make a MYSQL table and what can i do to solve this problem. Today i'm using a newby variable thing that i don't even wanna show because it sux.

If any of you have good solutin for this please let me know.

Thank you

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 01 September 2006 - 11:22 AM

Id go for something like this...









SizeType
SizeTypeIDChartNameDescription
1UKSHOEUK Shoe Sizes
2EUROPESHOEEuropean Shoe Sizes
3UKMALEWAISTMale waist size UK
4UKFEMALESKIRTFemale skirt size UK
5UKMARKETStandard UK Market size


















Sizes
SizeIDSizeChartIDSize
118
219
3110
4242
5243
6244
7338
8410
9412
105S
115M
125L
135XL


This is your existing product table... Just add a 'size' column linked to the UniqueID of the SizeType table







Product
ProductIDNameSizeColourPrice
1Nike Air Max1Red35.00
2Nike Air Zoom (US)2Blue40.00
3Silk Skirt4Black22.00
4Mens Cargo Trousers3Khaki37.00


You can add an additional table in there for specific product sizes.  e.g. if Nike Air Zoom (US) only come in size 43.

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 maziagha

maziagha
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 01 September 2006 - 11:33 AM

ok! looks pretty good
So if i want a product that i only have in S and M only what do i do then?
Yeah also i want it to be a List drop down menu to choose the sizes.

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 01 September 2006 - 12:02 PM

Maybe another table similar to this:









ProductQuantity
QuantityIDQProdIDQSizeIDQuantity
14101
24111
3146
4153
5163


I'm not sure this is 100% effecient, but it should work.  QuantityID is another unique value, QProdID is linked to your ProductID in your product table, QSizeID is linked to SizeID in your Sizes table and quantity is the amount you have.

That way you could only display the sizes of what you have in stock.  Some SQL something similar to this...

SELECT Size
FROM Sizes
WHERE SizeID IN (
     SELECT QSizeID
     FROM ProductQuantity
     WHERE QProdID = '$ProductID'
     AND Quantity != 0)

$ProductID is the variable passed from into the search from PHP.

I'm sure some DB experts could point you in a better direction, but this should work.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 maziagha

maziagha
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 01 September 2006 - 01:21 PM

That could work, but the process to add products would be to complicated.


#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 01 September 2006 - 01:27 PM

As you edited your post to include how you'd create the HTML for it, I'll have a stab at that too...

Lets say that you're information is going to be displayed on productdetail.php which is passed the ProductID in the URL from a previous page.

<?php
if (!isset($_POST['ProductID'])){
   header('Location: home.php'); // Lets redirect our users if they enter our page without a ProductID.
}
else{
   $ProductID = $_POST['ProductID'];
   include("connect.php"); // Include your connection strings in this seperate file
   $query = "SELECT Size FROM Sizes WHERE SizeID IN (SELECT QSizeID FROM ProductQuantity WHERE QProdID = '$ProductID' AND Quantity != 0)";

   $result = mysql_query($query); // Execute the query
   if (!$result){
      die('Could run query: ' .mysql_error());
   }

   while ($sizes = mysql_fetch_array($result, MYSQL_ASSOC)){  // While there are still rows, do this ...
      $option[]=$sizes["Size"]; //push the rows into a new array (we can do this as we know we're only selecting one column)
   }

   echo "<select name=\"sizes\">";
   foreach ($option as $size){
      echo "<option value=\"$size\">$size</option>\n"; // echo each individual item in the $option array
   }
   echo "</select>";

   include("disconnect.php"); // Include your disconnect details in a seperate file
}
?>

This should give you the values in a drop down list.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users