我有一个自定义表单,它有~6个自定义intuts,1-20可以是随机的,我如何获得$ _GET的随机输入并将它们放在col atributes
中:
<form method="GET" action="products.php" enctype="multipart/form-data">
<li>
<label>Name</label>
<input required class="scurtI" type="text" name="prod_name" value="<?= $_GET['prod_name'] ?>" placeholder="">
</li>
<li>
<label>Description</label>
<input required class="scurtI" type="text" name="prod_descr" value="<?= $_GET['prod_descr'] ?>" placeholder="">
</li>
<li>
<label>Meta - Title</label>
<input required class="scurtI" type="text" name="prod_meta_title" value="<?= $_GET['prod_meta_title'] ?>" placeholder="">
</li>
<li>
<label>Meta - Description</label>
<input required class="scurtI" type="text" name="prod_meta_desc" value="<?= $_GET['prod_meta_desc'] ?>" placeholder="">
</li>
<li>
<label>Meta - Keywords</label>
<input required class="scurtI" type="text" name="prod_meta_keys" value="<?= $_GET['prod_meta_keys'] ?>" placeholder="">
</li>
<li>
<label>Price</label>
<input required class="scurtI" type="text" name="prod_price" value="<?= $_GET['prod_price'] ?>" placeholder="">
</li>
<li>
<label>Currency</label>
<select name="prod_curency" class="focusSelect">
<option value="RON">RON</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
</select>
</li>
<li>
<label>Units</label>
<input required class="scurtI" type="text" name="prod_units" value="<?= $_GET['prod_units'] ?>" placeholder="">
</li>
<li>
<label>Category</label>
<select name="prod_ctgy" class="focusSelect">
<?php
$sql = "SELECT * FROM `categorii` WHERE `cat_id`";
$connect = mysqli_query($db_connect, $sql);
while (($item = mysqli_fetch_array($connect)))
{
?>
<option
value="<?= $item['cat_id'] ?>"><?= str_repeat(' ', 6 * $item['section_level']) ?><?= $item['section_name'] ?></option>
<?php
}
?>
</select>
</li>
<li>
<label>Manufacturer</label>
<select name="prod_manu" class="focusSelect">
<?php
$sql = "SELECT * FROM `manufactures` WHERE `id`";
$connect = mysqli_query($db_connect, $sql);
while (($item = mysqli_fetch_array($connect)))
{
?>
<option
value="<?= $item['manu_code'] ?>"><?= $item['manu_name'] ?></option>
<?php
}
?>
</select>
</li>
<li>
<label>Atributes</label>
<select name="prod_atr_id" class="focusSelect">
<?php
if (isset($_GET['prod_atr_id'])){
echo "<option selected value=".$_GET['prod_atr_id'].">Selected</option>";
}
$sql = "SELECT * FROM `products_atributes` WHERE `prod_atr_id`";
$connect = mysqli_query($db_connect, $sql);
while (($item = mysqli_fetch_array($connect)))
{
?>
<option
value="<?= $item['prod_atr_id'] ?>"><?= $item['prod_atr_name'] ?></option>
<?php
}
?>
</select>
<button class="btn btn-sm btn-primary" type="submit" name="next_add_product">Next</button>
</li>
<?php
if(isset($_GET['prod_atr_id']))
{
list_atributes($_GET['prod_atr_id']);
?>
<li>
<label>Main Image </label>
<input type="file" name="prod_image" style="">
</li>
<li>
<input class="btn btn-sm btn-primary" type="submit" name="prod_add_new" value="Add Product">
</li>
</form>
<?php
}
if(isset($_GET['prod_add_new']))
{
//$prod_name = $_GET['prod_name']
foreach($_GET as $key => $value){
echo $key . " : " . $value . "<br />\r\n";
}
//print_r($all_gets);
}
?>
function list_atributes($id)
{
global $db_connect;
$atribute_detect = $id;
if ($atribute_detect > 0){
$sql = "SELECT * FROM `products_atributes` WHERE `prod_atr_parent` = '".$atribute_detect."'";
$connect = mysqli_query($db_connect, $sql);
$count = mysqli_num_rows($connect);
if ($count == 0)
{
$sql = "SELECT * FROM `products_atributes` WHERE `prod_atr_id` = '".$atribute_detect."'";
}
if ($count > 0)
{
$sql = "SELECT * FROM `products_atributes` WHERE `prod_atr_parent` = '".$atribute_detect."'";
}
$connect = mysqli_query($db_connect, $sql);
while (($item = mysqli_fetch_array($connect)))
{
echo "
<li>
<label>".$item['prod_atr_name']."</label>
<input required class='scurtI' type='text' name='".$item['prod_atr_code']."' value='".$_GET[$item['prod_atr_code']]."' >
</li>
";
}
}
}
现在我得到了这个结果
我如何获得这个值,对于所有前缀为prod_
的人我都有特殊的cols,对于有数字的我必须将它们全部放在一个col中,然后我必须使用它们来提取为id = 40320861 value = 2000mb等。我如何构建代码以在单个列中添加db随机数$ _GET值
答案 0 :(得分:1)
我对这个问题的理解是你需要保存以下GET变量:
26126933:1243ghz
40320861:2000mb
47789694:64位
在单个db列中,随机生成密钥(未知)。
解答:
将属性保存在多维数组中,为此将html中的名称值设置为prod_attr_value[][$RANDOM_NUMBER]
,这将使数组中的属性值为$ _GET ['prod_attr_value']。
然后,要在单个db列中保存这些值,您只需json_encode($ arr)。
HTH
更新:
<input required class='scurtI' type='text' name='".$item['prod_atr_code']."' value='".$_GET[$item['prod_atr_code']]."' >
上面创建了一个$ _GET var,其中一个键的名称(不是值)为$ item ['prod_atr_code']。
将名称更改为prod_attr_values_arr[][$item['prod_atr_code']]
,将在发送请求时创建一个数组$ GET ['prod_attr_values_arr']