title: Dynamic variable based on database record/recall - Help?
body: <p>OK, I'll keep this as short as I can..</p>
  
  <p>I am trying to create a truly scalable environment for my users and so allow them to..<br>
  1. define a new option (dshop_options_name)<br>
  2. define option values (dshop_options_values)<br>
  separate tables in the database</p>
  
  <p>This is to allow distinct values to be assigned and also in any combination.<br>
  OK, the script is in 2 parts. The form page and the result page</p>
  
  <p><strong>form.php (using POST)</strong></p>
  
  <p>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</p>
  
  <p>//////////////////////////////////////////////////////////////////////////////////////////</p>
  
  <pre><code>$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 =&gt; $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"&lt;div class='left'&gt;";
    echo"$prod_prop_title\n";?&gt;
      &lt;select name='&lt;? echo $prod_prop_title?&gt;'&gt;
      &lt;option value="select"&gt;Select&lt;/option&gt;
      &lt;?php   
    foreach($prod_prop_attri_array as $rowNum =&gt; $data10){
    $itemname=$data10[2];
    $itemvalue=$data10[3];
    $itemprice=$data10[4];
    if($itemprice&lt;="0"){
    echo"&lt;option value='".$itemvalue."'&gt;".$itemvalue."&lt;/option&gt;\n";
    }
    else{
    echo"&lt;option value='".$itemvalue."'&gt;".$itemvalue."&amp;nbsp;-&amp;nbsp;".$currency_type.$itemprice."&lt;/option&gt;\n";
    }      
    }
    echo"&lt;/select&gt;&lt;/br&gt;&lt;/br&gt;&lt;/div&gt;";
    }
  </code></pre>
  
  <p>}</p>
  
  <p>//////////////////////////////////////////////////////////////////////////////////////////</p>
  
  <p>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.</p>
  
  <p><strong>result.php</strong></p>
  
  <p>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.</p>
  
  <p>//////////////////////////////////////////////////////////////////////////////////////////</p>
  
  <pre><code>$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 =&gt; $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&lt;=0;$i++){$options.=$results[$i]." | ";}
    }
  }
  </code></pre>
  
  <p>//////////////////////////////////////////////////////////////////////////////////////////</p>
  
  <p>ok, down to the issue...</p>
  
  <p>in the form.php, I am posting a value dynamically created, essentially by the admin user.</p>
  
  <p>Lets say they created an option "Foo", and the values "foo1", "foo2", "foo3" (in the admin area)</p>
  
  <p>form.php builds the selects by cross referencing the two tables, names the select and then populates it (nothing is pre-defined)</p>
  
  <p>then the end user arrives at the form on the front end and on posting the form, they selected "foo3"</p>
  
  <p>result.php at first has nothing to <code>_REQUEST</code> (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...<br>
  <code>$varnval = $_REQUEST[$option_name];</code> </p>
  
  <p>I then filter the names that have not been posted with..<br>
  <code>if(!$varnval | $varnval=="select"){}</code></p>
  
  <p>now...</p>
  
  <p>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.</p>
  
  <p>I placed an <code>echo</code> after the <code>$varnval $_REQUEST</code>, but nothing displays.</p>
  
  <p>It seems to me that the <code>$_REQUEST</code> is not getting the variable, either because of the parse or because I have just missed something.</p>
  
  <p>I have spent days working on this, trying many different ways but all threads lead nowhere.</p>
  
  <p>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)</p>
  
  <p>This is my first post here, so i apologise if it is in the wrong place!</p>
  
  <p>I thank you in advance for any help</p>