Is there a way to keep passing a value, submitted in the first (or earlier) dropdown select form to succeeding processing codes/files– AFTER THE FIRST PROCESSING FILE?
Here’s what I’m trying to do: I’ve created a db for footwear (size, type, style tables), then I created a lookup table called “syle_in_size” that has size relative to style. The idea is for queries to start from this table so that everything is based on the SIZE that the user selects at the beginning of the search. From there, the SPECIFIC footwear (size, style then type) will be determined.
So I came up with code that passes from one dropdown/ option table to another (I know, different pages*** I’ve seen advise and pages that do it all in one page but I want to do it in succession—partly as a design element and also because I do not know javascript since I only started with programming a few months ago–just one language at a time).
Here’s what I have:
SIZE Table
+--------+------+
| sizeid | size |
+--------+------+
| 7.0 | 7.0 |
| 7.5 | 7.5 |
| 9.0 | 9.0 |
| 9.5 | 9.5 |
| 11.0 | 11.0 |
+--------+------+
TYPE Table
+--------+---------+
| typeid | type |
+--------+---------+
| 1 | Shoes |
| 2 | Boots |
| 3 | Sandals |
+--------+---------+
STYLE Table
+---------+--------+------------+
| styleid | typeid | style |
+---------+--------+------------+
| 1 | 1 | Athletic |
| 2 | 1 | Lace-up |
| 3 | 1 | Loafers |
| 4 | 1 | Moccasins |
| 5 | 2 | Combat |
| 6 | 2 | Hiking |
| 7 | 2 | Riding |
| 8 | 3 | Flip Flops |
| 9 | 3 | Slide |
+---------+--------+------------+
STYLE_IN_SIZE Table
+---------------+--------+---------+
| sizeinstyleid | sizeid | styleid |
+---------------+--------+---------+
| 1 | 7.0 | 1 |
| 2 | 7.5 | 1 |
| 3 | 11.0 | 1 |
| 4 | 7.5 | 2 |
| 5 | 9.0 | 2 |
| 6 | 7.5 | 3 |
| 7 | 11.0 | 3 |
| 8 | 7.0 | 4 |
| 9 | 7.5 | 4 |
| 10 | 9.0 | 4 |
| 11 | 11.0 | 5 |
| 12 | 9.0 | 6 |
| 13 | 11.0 | 6 |
| 14 | 7.5 | 7 |
| 15 | 9.0 | 7 |
| 16 | 11.0 | 7 |
| 17 | 7.5 | 8 |
| 18 | 9.0 | 8 |
| 19 | 11.0 | 8 |
| 20 | 7.0 | 9 |
+---------------+--------+---------+
First page: SELECT_SIZE.php
<?php
$con = mysql_connect("localhost", "xxxxx", "xxxxx") or die('Could not connect to server');
mysql_select_db("footwear", $con) or die('Could not connect to database');
echo "<form action=\"select_type.php\" method=\"get\">\n";
echo "<select name=\"size\">\n";
$query="SELECT sizeid,size FROM size WHERE sizeid";
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$sizeid= $row['sizeid'];
$size= $row['size'];
echo "<option value=\"$sizeid\">$size</option>";
}
echo "</select>\n";
echo "<input name=\"submit\" type=\"submit\" id=\"sizeid\" value=\"submit\" />\n";
echo "</form> \n";
?>
First Processing page: SELECT_STYLE.php
After user selects size, code looks for all footwear type only available in that size. You’ll notice there are none in 9.5–that’s my little test.
<?php
$con = mysql_connect("localhost", "xxxxx", "xxxxx") or die('Could not connect to server');
mysql_select_db("footwear", $con) or die('Could not connect to database');
$sizeid= $_GET['sizeid'];
$size= $_GET['size'];
$query="SELECT sizeid,size FROM size WHERE sizeid=$size";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC) or die(mysql_error());
$sizeid= $row['sizeid'];
$size= $row['size'];
{
echo "<form action=\"select_style.php\" method=\"get\">\n";
echo "<select name=\"type\">\n";
$query="SELECT DISTINCT type.typeid, type, style_in_size.sizeid FROM style_in_size, type, style, size
WHERE style_in_size.sizeid=$sizeid
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid
GROUP BY type";
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$sizeid = $row['sizeid'];
$size= $row['size'];
$typeid = $row['typeid'];
$type=$row['type'];
echo "<option value=\"$typeid\" \"$sizeid\">$type $sizeid</option>";
//I want only the "type" /$type to show in the dropdown but included SIZE for now to see if it would help pass the value to the next page
}
echo "</select>\n";
echo "<input name=\"submit\" type=\"submit\" id=\"typeid\" value=\"submit\" />\n";
echo "</form> \n";
}
?>
Passes on to this page where I want to show type and size (for now, because I want to create another dropdown for style BASED ON SIZE. But if I can’t get size to show up on this page then I can’t proceed)
SELECT_STYLE.php
<?php
$con = mysql_connect("localhost", "xxxxx", "xxxxx") or die('Could not connect to server');
mysql_select_db("footwear", $con) or die('Could not connect to database');
$sizeid = $_GET['sizeid'];
$size= $_GET['size'];
$typeid = $_GET['typeid'];
$type=$_GET['type'];
$query = "SELECT type, style_in_size.sizeid FROM size, type, style, style_in_size
WHERE type.typeid=$type
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid
AND style_in_size.sizeid = size.sizeid";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC) or die(mysql_error());
$sizeid = $row['sizeid'];
$size= $row['size'];
$typeid = $row['typeid'];
$type=$row['type'];
{
echo "You've chosen $type in size $size ";
}
?>
If I select “Sandals”, the preceding code only displays “You’ve chosen Sandals in ” ; size does not show/ was not passed.
I’ve tried the following but nothing works:
$query = "SELECT type.typeid, type, style_in_size.sizeid FROM size, type, style, style_in_size
WHERE type.typeid=$type
AND sizeid = $sizeid
AND size.sizeid = style_in_size.sizeid
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid";
Also:
$query = "SELECT type.typeid, type, style_in_size.sizeid FROM size, type, style, style_in_size
WHERE style_in_size.sizeid = $sizeid
AND size.sizeid = style_in_size.sizeid
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid
AND typeid=$type";
I hope I’ve written my question in a manner that makes sense.
Your help and input are greatly appreciated.
Thanks in advance.
Considering you’re doing this over multiple pages the best solution is probably to make use sessions (see here).
When you get, say, the size you can store this in the session:
In later pages you can retrieve this:
(Note: Make sure you call
session_start()at the start of pages using sessions).Also as Charles mentioned you should take steps to prevent SQL Injection. the mysql_* are now deprecated.