1

我喜欢下面:

<form name="crea">
        <table class="table table-striped table-bordered table-condensed">
            <thead>
                <tr>
                    <th>Articolo</th>
                    <th>Pellame</th>
                    <th>Colore</th>
                    <th>Fondo</th>
                    <th>Taglia</th>
                    <th>Quantit&agrave;</th>
                    <th>+/-</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <input type="text" name="articolo[]" class="input-small" />
                    </td>
                    <td>
                        <select name="pellame[]" class="input-medium">
                            <option value="nabuk">Nabuk</option>
                            <option value="vitello">Vitello</option>
                            <option value="capretto">Capretto</option>
                        </select>
                    </td>
                    <td>
                        <select name="colore[]" class="input-medium">
                            <option value="nero">Nero</option>
                            <option value="blu">Blu</option>
                            <option value="rosso">Rosso</option>
                            <option value="bianco">Bianco</option>
                            <option value="argento">Argento</option>
                            <option value="platino">Platino</option>
                            <option value="bronzo">Bronzo</option>
                            <option value="tortora">Tortora</option>
                        </select>
                     </td>
                    <td>
                        <select name="fondo[]" class="input-medium">
                            <option value="gomma">Gomma</option>
                            <option value="cuoio">Cuoio</option>
                            <option value="sughero">Sughero</option>
                        </select>
                    </td>
                    <td>
                        <select name="taglia[]" class="input-mini">
                            <option value="35">35</option>
                            <option value="36">36</option>
                            <option value="37">37</option>
                            <option value="38">38</option>
                            <option value="39">39</option>
                            <option value="40">40</option>
                            <option value="41">41</option>
                            <option value="42">42</option>
                            <option value="43">43</option>
                            <option value="44">44</option>
                            <option value="45">45</option>
                            <option value="46">46</option>
                            <option value="47">47</option>
                        </select>
                    </td>
                    <td>
                        <input type="number" min="1" max="200" name="qnt[]" step="1" value="1" class="input-mini"/>
                    </td>
                    <td></td>
                </tr>
            </tbody>

        </table>
                <input type="submit" class="btn btn-primary" name="genera" value="Genera" />

    </form>

我在 ajax (jquery.post) 中提交了这个表单。在服务器端 PHP 接收数据,我需要打印提交表单的简历。例如是用户输入(对于行):

ART1 - nabuk - 尼禄 - gomma - 35 - 1

ART1 - nabuk - 尼禄 - gomma - 39 - 5

ART1 - nabuk - 尼禄 - gomma - 40 - 9

ART1 - nabuk - 尼禄 - gomma - 45 - 1

ART1 - nabuk - rosso - gomma - 38 - 1

ART1 - nabuk - rosso - gomma - 38 - 1

ART1 - nabuk - 尼禄 - gomma - 38 - 1

ART1 - vitello - 蓝光 - gomma - 38 - 1

ART1 - vitello - 蓝光 - gomma - 40 - 1

ART561 - nabuk - 尼禄 - gomma - 40 - 1

简历将按前 4 个字段过滤,例如:

ART1 - nabuk  - nero - gomma

                                                            35->1
                                                            39->5
                                                            40->9
                                                            45->1 

另一份简历将是:

ART1 - vitello - blu - gomma 

                                                            38->1
                                                            40->1

所以4个字段是过滤条件,另外4个是每个过滤规则的公共数据。该表使用javascript在高度上动态扩展/减少,我的问题是如何过滤发送到PHP的帖子数据的示例。 然后将它们写入文件,不是问题......

简历将打印在 PDF 文件上(这不是问题)。我已经尝试过foreach cicle,但我不知道如何选择标准......我认为这非常困难。(程序没有数据库)

任何人都可以帮助我吗?太感谢了

4

1 回答 1

0

我想我明白你想要做什么。以正确的方式将所有帖子数据添加到数组中,然后使用 array_multisort 应该负责您的过滤,以升序方式对简历进行排序。

我认为以下应该可以得到你的结果。请注意,您确实应该在表单标签 (action="mypage.php") 中添加一个操作,并且可能还有 method="post"。祝你好运。见下文。我希望这有帮助。

为了便于使用,我假设您也希望将输出放在表格中,但这很容易更改为 PDF 或其他内容的字符串。

//if all post variables are at least set...
if(isset($_POST['articolo']) && $_POST['articolo']!=''
    && isset($_POST['pellame']) && $_POST['pellame']!=''
    && isset($_POST['colore']) && $_POST['colore']!=''
    && isset($_POST['fondo']) && $_POST['fondo']!=''
    && isset($_POST['taglia']) && $_POST['taglia']!=''
    && isset($_POST['qnt']) && $_POST['qnt']!=''){

//resumes array
$resumes = array();

//Loop through each post row (based on the articolo), if all the same keys are set for the required post we have
// a valid resume.
foreach($_POST['articolo'] as $key=>$value){
    if(isset($_POST['articolo'][$key]) && $_POST['articolo'][$key]!=''
        && isset($_POST['pellame'][$key]) && $_POST['pellame'][$key]!=''
        && isset($_POST['colore'][$key]) && $_POST['colore'][$key]!=''
        && isset($_POST['fondo'][$key]) && $_POST['fondo'][$key]!=''
        && isset($_POST['taglia'][$key]) && $_POST['taglia'][$key]!=''
        && isset($_POST['qnt'][$key]) && $_POST['qnt'][$key]!=''){
        $resumes[] = array('articolo'=>$_POST['articolo'][$key],
            'pellame'=>$_POST['pellame'][$key],
            'colore'=>$_POST['colore'][$key],
            'fondo'=>$_POST['fondo'][$key],
            'taglia'=>$_POST['taglia'][$key],
            'qnt'=>$_POST['qnt'][$key]);
    }
}

//Multi sort our resumes array ASCENDING for each key.
array_multisort($resumes);

//set up our "current" article to start with, the details are blank so we print the first details always.
$current['articolo'] = '';
$current['pellame'] = '';
$current['colore'] = '';
$current['fondo'] = '';

//start output
echo '<table>';

//loop through the resumes
foreach($resumes as $thisResume){

    //Print this row
    echo '<tr><td>';
    //If this resume is of a different type (any of the keys/filters) then print the info, otherwise it's the
    // same as above so don't bother.
    if($thisResume['articolo']!=$current['articolo']
            || $thisResume['pellame']!=$current['pellame']
            || $thisResume['colore']!=$current['colore']
            || $thisResume['fondo']!=$current['fondo']){
        echo htmlentities($thisResume['articolo']
                .' - '.$thisResume['pellame']
                .' - '.$thisResume['colore']
                .' - '.$thisResume['fondo']);

    }
    //Echo the resume specific quantity info.
    echo '</td><td>'.htmlentities($thisResume['taglia']
                .' -> '.$thisResume['qnt']).'</td></tr>';

    //Update our current array info which stores the resume attributes for comparison of next resume.
    $current['articolo'] = $thisResume['articolo'];
    $current['pellame'] = $thisResume['pellame'];
    $current['colore'] = $thisResume['colore'];
    $current['fondo'] = $thisResume['fondo'];
}
//end output
echo '</table>';
}
?>
于 2012-06-12T12:24:24.817 回答