OK, I'll keep this as short as I can..
I am trying to create a truly scalable environment for my users and so allow them to..
1. define a new option (dshop_options_name)
2. define option values (dshop_options_values)
separate tables in the database
This is to allow distinct values to be assigned and also in any combination.
OK, the script is in 2 parts. The form page and the result page
form.php (using POST)
first I need to create dropdowns dynamically based on the options assigned to the product, and then run through the dshop_options_values table to get any values assigned to that option
//////////////////////////////////////////////////////////////////////////////////////////
$prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`");
$prod_prop_name_array= array();
while($data9=mysql_fetch_array($prod_prop_name)) {
$prod_prop_name_array[]=$data9;
}
foreach($prod_prop_name_array as $rowNum => $data9) {
$prod_prop_id=$data9[0];
$prod_prop_title=$data9[1];
$prod_prop_attri=mysql_query("SELECT * FROM `dshop_options_values` WHERE `prod_id`='".$selected_product."' AND `attri_name`='".$prod_prop_title."' ORDER BY `attri_value` ASC ");
$prod_prop_attri_array= array();
while($data10=mysql_fetch_array($prod_prop_attri)) {
$prod_prop_attri_array[]=$data10;
}
if(!$prod_prop_attri_array){}
else{
echo"<div class='left'>";
echo"$prod_prop_title\n";?>
<select name='<? echo $prod_prop_title?>'>
<option value="select">Select</option>
<?php
foreach($prod_prop_attri_array as $rowNum => $data10){
$itemname=$data10[2];
$itemvalue=$data10[3];
$itemprice=$data10[4];
if($itemprice<="0"){
echo"<option value='".$itemvalue."'>".$itemvalue."</option>\n";
}
else{
echo"<option value='".$itemvalue."'>".$itemvalue." - ".$currency_type.$itemprice."</option>\n";
}
}
echo"</select></br></br></div>";
}
}
//////////////////////////////////////////////////////////////////////////////////////////
ok, as you can see, I name the select the same as the option name, this is so I then use that name to again call the value in the next script.
result.php
Ok, to reasemble the data set and match up the result to the data posted, I again, do a few calls to get all the data first.
//////////////////////////////////////////////////////////////////////////////////////////
$prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`");
$prod_prop_name_array= array();
while($data9=mysql_fetch_array($prod_prop_name)) {
$prod_prop_name_array[]=$data9;
}
foreach($prod_prop_name_array as $rowNum => $data9){
$option_id=$data9[0];
$option_name=$data9[1];
$varnval=$_REQUEST[$option_name];
echo"$varnval"; // did we get a result?
$results = array();
if(!$varnval | $varnval=="select"){}
else{
$results[] = $option_name."-".$varnval;
$optpricesum_query=mysql_query("SELECT * FROM `dshop_options_values` WHERE `attri_name`='".$option_name."' AND `attri_value`='".$varnval."'");
$optpricesum_result=mysql_fetch_array($optpricesum_query);
$optpricesum=$optpricesum_result[4];
}
if(!$varnval | $varnval=="select"){}
else{
for ($i=0;$i<=0;$i++){$options.=$results[$i]." | ";}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
ok, down to the issue...
in the form.php, I am posting a value dynamically created, essentially by the admin user.
Lets say they created an option "Foo", and the values "foo1", "foo2", "foo3" (in the admin area)
form.php builds the selects by cross referencing the two tables, names the select and then populates it (nothing is pre-defined)
then the end user arrives at the form on the front end and on posting the form, they selected "foo3"
result.php at first has nothing to _REQUEST
(remember we had nothing to define) until it rebuilds the possible vaiables that could have been posted.
I then used the foreach to run through all the option names stored with the hope of then creating dynamic variables...
$varnval = $_REQUEST[$option_name];
I then filter the names that have not been posted with..
if(!$varnval | $varnval=="select"){}
now...
Locally I get the value "foo3" no problem, but not on the web server. I then noticed that when using local php (Xampp) values dont even need to be defined $var=$_POST['var']; it will still work.... annoying when debugging!! BUT shows to a point anyways, that the script will work.
I placed an echo
after the $varnval $_REQUEST
, but nothing displays.
It seems to me that the $_REQUEST
is not getting the variable, either because of the parse or because I have just missed something.
I have spent days working on this, trying many different ways but all threads lead nowhere.
Maybe I am trying the impossible, but I feel there has to be a way to create a set of variables from database records alone (NOT the other way around as most searches seem to produce)
This is my first post here, so i apologise if it is in the wrong place!
I thank you in advance for any help