Forum Moderators: coopster
This code is actually inserted immediately after the first Select statement, and includes the options, and a second select statement and it's options. The second Select statement is named VARname, and returns the selected value ($Desc) back to the <option> of the first Select statement.
How do I return the value of $ItemID to the first option group? Somehow, I need a pair value for the select VARname.
<?php
$link1 = mysql_connect("localhost", "myid", "mypwd") or die("Could not connect : " . mysql_error());
mysql_select_db("my_db") or die("Could not select database");
$pricequery = "SELECT DISTINCT * FROM table1 WHERE field1 = 'value1' OR field1 = 'value2' OR field1 = 'value3'";
$priceresult = mysql_query($pricequery) or die("Query failed : " . mysql_error());
while ($priceline = mysql_fetch_array($priceresult, MYSQL_ASSOC)) {
$Package = $priceline['field3'];
$Price = $priceline['field2'];
$Pack = $priceline['field1'];
echo "<option value=\"VARname¦$Price¦VARquantity¦$ItemID $Pack¦¦prompt¦\.02¦¦\">$Package</option>"; }
echo "</select>";
echo "<br><br>Your Choice: <select name=\"VARname\" size=\"1\">";
$query = "SELECT * FROM table2 ORDER BY field1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$ItemID = $line['field1'];
$Desc = $line['field2'];
echo "<option value=\" $Desc \">$Desc</option>"; }
?>
Could you JOIN the tables together in order to build the first select list? That way the value is already present...? Can you give some details on what you want to do, grandpa? That would help tremendously. We have the code snippet, but need clarification. Thanks.
That's an accurate interpretation coopster.
I don't know if a JOIN is the answer. Shortly after I posted that message, however, the solution may have come to me. But the solution goes into that 'gray-area' where I always get myself into trouble with UNIX. And, the solution has nothing to do with PHP...
It seems to me the best solution is this: I need to create a new table that combines two existing tables, then query the new table.
Table3 (new table) needs to read each row of table1. For each row of table1 I need to read table2 and add a new record. Basically, a while loop inside another while loop.
While (record table1){
while (record table2) {}
}
It's got be something I can run whenever I change products or prices.
Allow me to run on a minute longer - and still off topic - and describe my data tables.
What I have in table1 is a list of product PartID's and Descriptions. table2 contains my Prices and Sizes. The reason these aren't in a single table is clear... to me. Let me explain...
Table1 has 326 rows, table2 has 33 rows. Each row in each table is unique. Maintenance of parts and prices is very easy. But if put it all together in a single table, I end up with 10,758 rows, which suddenly is a bear to maintain. Change a price? You change it 326 times. Add an item, you add it 33 times (once for each price). That's what I do now for my accounting database, and it's not fun, and I'm not going down that road again.
Back on topic for a minute, then I'm done.
The code I posted is inside a form. There are 11 forms on my page. What I saw was in the second, and subsequent forms, the value I was looking for, $ItemID, does appear. But the value of $ItemID is the last record from the previous query. Blech!
I'll go and research JOIN and see if I can build a query that doesn't bring my hosts server to it's knees. If I could assign a pair-value to my html Select Name life would be so much easier.