插入的数据总是导致Upland,即使我选择了Tab-pane Irrigated或Rainfed,使用echo仍然是相同的结果。很抱歉发布了一个常见问题。我是数组插入数据库的新手。
$types = array(
'irrigated' => 'Irrigated',
'rainfed' => 'Rainfed',
'upland' => 'Upland'
);
$seed_types = array(
'hybrid_' => 'Hybrid',
'taggedSeeds_' => 'Tagged Seeds from (RS/FS/CS)',
'goodSeedsTagged_' => 'Good Seeds from Tagged FS/RS',
'goodSeedsStarter_'=>'Good Seeds from Starter RS/CS',
'goodSeedsTraditional_'=>'Good Seeds of Traditional',
'farmSaved_'=>'Farm Saved Seeds'
);
foreach($types as $type){
echo '<div id="'.$type.'" class="tab-pane fade tab-title">';
echo "<br/>".$type."<hr/>";
echo "<input type='hidden' name='ecosystem' value='".$type."'>";
foreach($seed_types as $seed_name => $seed_type){
echo '<div class="row form-group">';
echo '<div class="col-md-4 table-body">'.$seed_type.'</div>';
for ($x = 0; $x <= 3; $x++) {
echo '<div class="col-md-2"><input type="number" class="form-control" name="'.$seed_name.''.$x.'" /></div>';
}
echo "</div>";
}
echo '</div>';
}echo '<div class="row" style="border-top:dashed 1px #eaeaea;padding-top:15px;">
<div class="col-md-11" style="text-transform:initial;">Note: Kindly check all the data before saving. Thank You.</div>
<div class="col-md-1">
<input type="submit" name="save-report" value="Save Data!" class="btn btn-success">
</div>
</div>';
echo '</div>';
<?php
if (isset($_POST['save-report'])) {
// Process
global $wpdb;
$ecosystem = $_POST['ecosystem'];
$result = $wpdb->insert('wp_sample', array (
'eco_system' => "$ecosystem",
'type' => "$seed_type",
));
}
答案 0 :(得分:0)
试试这样。
$types = array(
'irrigated' => 'Irrigated',
'rainfed' => 'Rainfed',
'upland' => 'Upland'
);
$seed_types = array(
'hybrid_' => 'Hybrid',
'taggedSeeds_' => 'Tagged Seeds from (RS/FS/CS)',
'goodSeedsTagged_' => 'Good Seeds from Tagged FS/RS',
'goodSeedsStarter_'=>'Good Seeds from Starter RS/CS',
'goodSeedsTraditional_'=>'Good Seeds of Traditional',
'farmSaved_'=>'Farm Saved Seeds'
);
foreach($types as $type){
echo '<div id="'.$type.'" class="tab-pane fade tab-title">';
echo "<br/>".$type."<hr/>";
echo "<input type='hidden' name='ecosystem[]' value='".$type."'>";
foreach($seed_types as $seed_name => $seed_type){
echo '<div class="row form-group">';
echo '<div class="col-md-4 table-body">'.$seed_type.'</div>';
for ($x = 0; $x <= 3; $x++) {
echo '<div class="col-md-2"><input type="number" class="form-control" name=[number]["'.$seed_name.''.$x.']" /></div>';
}
echo "</div>";
}
echo '</div>';
}echo '<div class="row" style="border-top:dashed 1px #eaeaea;padding-top:15px;">
<div class="col-md-11" style="text-transform:initial;">Note: Kindly check all the data before saving. Thank You.</div>
<div class="col-md-1">
<input type="submit" name="save-report" value="Save Data!" class="btn btn-success">
</div>
</div>';
echo '</div>';
<?php
if (isset($_POST['save-report'])) {
// Process
global $wpdb;
foreach($_POST['ecosystem'] as $key => $value){
$ecosystem = $value;
$result = $wpdb->insert('wp_sample', array (
'eco_system' => $ecosystem,
'type' => $seed_type,
));
}
}