简体   繁体   English

PHP MySQL选择不同的值

[英]php mysql select with different values

I have a table with exercises and I want to generate I want that the visitor can select the number of exercises that him wants... every exercise must be appear in a different select and I need that the first value in every select will be different. 我有一个包含练习的表格,我想生成一个表格,希望访问者可以选择他想要的练习数量...每个练习必须出现在不同的选择中,并且我需要每个选择中的第一个值都应不同。 I have this code: 我有以下代码:

<form class="form-horizontal" action="wod_auto_sartu.php" method="post" enctype="multipart/form-data">
<?php
$numbers = range(1, 12);
shuffle($numbers);
for ($i=1;$i<=$num_jornadas;$i++){
    $numbers2=$numbers[$i];
    $random_wod=$wod[$numbers2];
?>
    <div class="form-group">
        <label for="inpuName" class="col-md-4 control-label"><font color="#fff"><b><?php echo _("Jornada: $i"); ?></b></font></label>
        <div class="col-md-6">
            <select class="form-control  c-square c-theme" id="wod" style="opacity: .8;max-width:80%;" name="num_jornadas" method="post">
<?php
    foreach ($numbers as $row){
        echo '<option value='. $random_wod[0] .'>'. $random_wod[1] .'</option>';
    }
?>
    </select>
        </div>
   </div>
<?php
}
?>

In this moment, I get info as I have mentioned, but if I unfold the select I get the same value in all options, I need as I said that the first option in every option will different but when I unfold, I need see all other exercises, not the same... 在这一刻,我得到了如上所述的信息,但是如果我展开选择,那么我在所有选项中都得到相同的值,我需要,因为我说过每个选项中的第一个选项都会有所不同,但是当我展开时,我需要查看所有其他练习,不一样...

How can I solve it? 我该如何解决?

Example image 范例图片

Problem solved!! 问题解决了!! I had an error of concept... I was introducing the same array all the time waiting for a different output ... as Einstein said... "Stupidity is repeating the same error expecting different results" 我有一个概念上的错误...我一直在引入相同的数组,等待不同的输出...正如爱因斯坦所说的...“愚蠢的重复相同的错误,期望得到不同的结果”

The correct code: 正确的代码:

<form class="form-horizontal" action="wod_auto_sartu.php" method="post" enctype="multipart/form-data">
<?php
$lista_wods = array();
foreach($wod as $row=>$value):
$lista_wods[] = '<option value="'.$row.'">' .$value[1].'</option>';
endforeach;

$numbers = range(1, 12);
shuffle($numbers);
for ($i=1;$i<=$num_jornadas;$i++){
    $numbers2=$numbers[$i];
    $random_wod=$wod[$numbers2];
?>
<div class="form-group">
    <label for="inpuName" class="col-md-4 control-label"><font color="#fff"><b><?php echo _("Jornada: $i"); ?></b></font></label>
    <div class="col-md-6">
        <select class="form-control  c-square c-theme" id="wod" style="opacity: .8;max-width:80%;" name="num_jornadas" method="post">
<?php
       print_r ('<option value='. $random_wod[0] .'>'. $random_wod[1] . '</option>');
       print_r(array_values($lista_wods));
?>
        </select>
    </div>
</div>
<?php
}
?>

Thanks to those who have tried to help me! 感谢那些试图帮助我的人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM