doulu4233 2009-11-23 00:19
浏览 31

基于数据库记录/召回的动态变量 - 帮助?

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
";?>
    <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>
";
  }
  else{
  echo"<option value='".$itemvalue."'>".$itemvalue."&nbsp;-&nbsp;".$currency_type.$itemprice."</option>
";
  }      
  }
  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

  • 写回答

1条回答 默认 最新

  • doutingyou2198 2009-11-23 10:00
    关注

    You should first check that 'register_globals' is on, in order to have $_REQUEST to work; i'd rather not use that superglobal variable but use $_GET or $_POST instead (depending on your form settings).

    For your options; it's better to store them as an array :

    <select name="myoption[]">
    <option name="1" value="1">One</option>
    <option name="2" value="2">Two</option>
    </select>
    

    Which in PHP will return an array that you can get using

    print_r($myoption);
    

    Hope that helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制