jonnyfortis Posted August 2, 2013 Share Posted August 2, 2013 i have a variable that is passed from a select list, the value of the select list is a stockID <?php echo $XCart_StockID = ${$XCName}["contents"][0][$XCart__i]; ?> this is constructed from an array $useSessions = false; $XCName = "mejobbo"; $XCTimeout = 1; $XC_ColNames=array("StockID","ProductID","Size","Quantity","Name","Price","Stock","Total"); $XC_ComputedCols=array("","","","","","","","Price"); require_once('XCInc/XCart.inc'); i have a tables that contains joined references mejobbo_products-----------------------------ProductIDthe stock tablemejobbo_Stock-----------------------------StockIDProductIDSizeIDand the size tablemejobbo_SizeList-----------------------------SizeIDSize i need to know how to get all the data from table mejobbo_Stock based on the <?php echo $XCart_StockID; ?> variable thanks Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/ Share on other sites More sharing options...
Muddy_Funster Posted August 2, 2013 Share Posted August 2, 2013 could you show some sample output? maybe a relevent section of the rendered pages source code as well? Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443111 Share on other sites More sharing options...
jonnyfortis Posted August 2, 2013 Author Share Posted August 2, 2013 (edited) thanks here is the product description page. including the select list that needs to pass the stockID // *** X Shopping Cart *** $useSessions = false; $XCName = "mejobbo"; $XCTimeout = 1; $XC_ColNames=array("StockID","ProductID","Size","Quantity","Name","Price","Stock","Total"); $XC_ComputedCols=array("","","","","","","","Price"); require_once('XCInc/XCart.inc'); $var1_rsProduct = "-1"; if (isset($_GET['productID'])) { $var1_rsProduct = $_GET['productID']; } mysql_select_db($database_mejobbo, $mejobbo); $query_rsProduct = sprintf("SELECT * FROM mejobboAW13_Cat, mejobboAW13_products, mejobboAW13_Stock, mejobboAW13_SizeList WHERE mejobboAW13_products.catID = mejobboAW13_Cat.catID AND mejobboAW13_products.ProductID = mejobboAW13_Stock.ProductID AND mejobboAW13_Stock.SizeID = mejobboAW13_SizeList.SizeID AND mejobboAW13_products.ProductID = %s AND mejobboAW13_Stock.Stock != 0 ", GetSQLValueString($var1_rsProduct, "int")); $rsProduct = mysql_query($query_rsProduct, $mejobbo) or die(mysql_error()); $row_rsProduct = mysql_fetch_assoc($rsProduct); $totalRows_rsProduct = mysql_num_rows($rsProduct); // *** Add item to Shopping Cart via form *** $XC_editAction1 = $_SERVER["PHP_SELF"]; if (isset($_SERVER["QUERY_STRING"])) $XC_editAction1 = $XC_editAction1 . "?" . $_SERVER["QUERY_STRING"]; if (isset($_POST["XC_addToCart"]) && $_POST["XC_addToCart"] == "form1") { $NewRS=mysql_query($query_rsProduct, $mejobbo) or die(mysql_error()); $XC_rsName="rsProduct"; // identification $XC_uniqueCol="ProductID"; $XC_redirectTo = ""; $XC_redirectPage = "../cart1.php"; $XC_BindingTypes=array("FORM","RS","FORM","LITERAL","RS","RS","RS","NONE"); $XC_BindingValues=array("size2","ProductID","size2","1","Product","Price","Stock",""); $XC_BindingLimits=array("","","","","","","",""); $XC_BindingSources=array("","","","","","","",""); $XC_BindingOpers=array("","","","","","","",""); require_once('XCInc/AddToXCartViaForm.inc'); } and the form <form action="<?php echo $XC_editAction1; ?>" method="post"> <select name="select" id="select"> <?php do { ?> <option value="<?php echo $row_rsProduct['StockID']; ?>"><?php echo $row_rsProduct['Size']?></option> <?php } while ($row_rsProduct = mysql_fetch_assoc($rsProduct)); $rows = mysql_num_rows($rsProduct); if($rows > 0) { mysql_data_seek($rsProduct, 0); $row_rsProduct = mysql_fetch_assoc($rsProduct); } ?> </select> <input type="image" src="../images/SS13AddToCart.jpg" border="0" name="submit"/></p> <input type="hidden" name="XC_recordId" value="<?php echo $row_rsProduct['ProductID']; ?>" /> <input type="hidden" name="XC_addToCart" value="form1" /> </form> then the page this is sent to is cart1.php // *** X Shopping Cart *** $useSessions = false; $XCName = "mejobbo"; $XCTimeout = 1; $XC_ColNames=array("StockID","ProductID","Size","Quantity","Name","Price","Stock","Total"); $XC_ComputedCols=array("","","","","","","","Price"); require_once('XCInc/XCart.inc'); then i tried a query to get the StockID details mysql_select_db($database_mejobbo, $mejobbo); $query_rsSize = "SELECT * FROM mejobboAW13_Stock, mejobboAW13_SizeList WHERE mejobboAW13_Stock.SizeID = mejobboAW13_SizeList.SizeID AND mejobboAW13_Stock.StockID = '$XCart_StockID'"; $rsSize = mysql_query($query_rsSize, $beau) or die(mysql_error()); $row_rsSize = mysql_fetch_assoc($rsSize); $totalRows_rsSize = mysql_num_rows($rsSize); but this didn't work then to diplay in a table <?php while($XCart__i<sizeof(${$XCName}["contents"][0])) { require('XCInc/RepeatXCartRegion.inc'); ?> <tr class="text"> <td><input name="Quantity[]" type="text" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>" size="2" maxlength="2" /></td> <td><?php echo $XCart_Name = ${$XCName}["contents"][4][$XCart__i]; ?></td> <td><?php echo $XCart_StockID = ${$XCName}["contents"][0][$XCart__i]; ?></td> <td><?php echo $XCart_Size = ${$XCName}["contents"][2][$XCart__i]; ?><?php echo $row_rsSize['Size']; ?></td> <td><?php echo DoFormatCurrency($XCart_Price = ${$XCName}["contents"][5][$XCart__i], 2, ',', '.', '£ ', ''); ?></td> <td><?php echo DoFormatCurrency($XCart_Total = ${$XCName}["contents"][7][$XCart__i], 2, ',', '.', '£ ', ''); ?></td> <td><input type="checkbox" name="xdelete<?php echo $XCart__i; ?>" value="1" /></td> </tr> <?php $XCart__i++; Next(${$XCName}["contents"][0]); } ?> is this what you asked for, thanks Edited August 2, 2013 by jonnyfortis Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443115 Share on other sites More sharing options...
lemmin Posted August 2, 2013 Share Posted August 2, 2013 Your code is hard to read in blocks like that. You have derived variable variables without showing their instantiation. Anyway, your form submits the StockID as a value of the "select" select (select named select). After submitting your form, $_POST['select'] will contain the StockID that was selected. You should then be able to use that variable in your query. Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443188 Share on other sites More sharing options...
jonnyfortis Posted August 2, 2013 Author Share Posted August 2, 2013 Your code is hard to read in blocks like that. You have derived variable variables without showing their instantiation. Anyway, your form submits the StockID as a value of the "select" select (select named select). After submitting your form, $_POST['select'] will contain the StockID that was selected. You should then be able to use that variable in your query. yes i get that bit but need to know how to make that query to get all the data based on that $XCart_StockID variable Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443232 Share on other sites More sharing options...
lemmin Posted August 2, 2013 Share Posted August 2, 2013 I'm just saying, I don't know what value $XCart_StockID holds, so it might not be what you expect. It NEEDS to have the value from the "select" element. Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443237 Share on other sites More sharing options...
jonnyfortis Posted August 2, 2013 Author Share Posted August 2, 2013 I'm just saying, I don't know what value $XCart_StockID holds, so it might not be what you expect. It NEEDS to have the value from the "select" element. sorry, yes that is the value from the select list.it is put into an array that is in the code above $XC_BindingValues=array("size2","ProductID","size2","1","Product","Price","Stock",""); Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443239 Share on other sites More sharing options...
lemmin Posted August 2, 2013 Share Posted August 2, 2013 So what isn't working? Is there just no output, or is there an error? Have you double checked that the ID you are using IS in the database along with an associated size in the related table? Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443247 Share on other sites More sharing options...
jonnyfortis Posted August 5, 2013 Author Share Posted August 5, 2013 So what isn't working? Is there just no output, or is there an error? Have you double checked that the ID you are using IS in the database along with an associated size in the related table? sorry a bit vague, yes there is no output yes all the IDs are corrected and the tables are related.. Quote Link to comment https://forums.phpfreaks.com/topic/280751-retrieve-table-data-based-on-a-single-variable/#findComment-1443525 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.