Php 如何修复嵌套循环,因为它显示每行的所有值,而不是每行一个值? 地区 计数 议论

Php 如何修复嵌套循环,因为它显示每行的所有值,而不是每行一个值? 地区 计数 议论,php,cakephp,loops,foreach,nested-loops,Php,Cakephp,Loops,Foreach,Nested Loops,您需要以某种方式构建该数组,以便知道在什么索引处有什么值,然后将该值打印出来,如$upc[$i] 另外,如果这是您真正的sql语句,您应该始终使用“”括起参数,并确保转义所有输入。您需要以某种方式构建该数组,以便知道在哪个索引处有什么值,然后打印出值,如$upc[$i] 另外,如果这是您真正的sql语句,您应该始终使用“”括起参数,并确保转义所有输入。解决方案是:数组$upc,索引为$i减1 <?PHP // areaList // [0] = Upstairs Tabl

您需要以某种方式构建该数组,以便知道在什么索引处有什么值,然后将该值打印出来,如$upc[$i]


另外,如果这是您真正的sql语句,您应该始终使用“”括起参数,并确保转义所有输入。

您需要以某种方式构建该数组,以便知道在哪个索引处有什么值,然后打印出值,如$upc[$i]


另外,如果这是您真正的sql语句,您应该始终使用“”括起参数,并确保转义所有输入。

解决方案是:数组
$upc
,索引为
$i
减1

<?PHP
    // areaList
    //  [0] = Upstairs Tables
    //  [1] = Upstairs Seats
    //  [2] = Upstairs TV
    //  [3] = Upstairs Computers
    //  [4] = Lounges SL
    //  [5] = Lounges BL
    //  [6] = Conference Room 216
    //  [7] = Conference Room 218
    //  [8] = Conference Room 219
    //  [9] = Conference Room 220
    // [10] = Cash 204
    // [11] = Cash 205
    // [12] = Cash 207
    // [13] = Downstairs Lobby
    // [14] = Downstairs Center
    // [15] = Downstairs Rec
    // [16] = Downstairs Computers
    // [17] = Games Bowling
    // [18] = Games Billiards
    // [19] = Games Arcade
    // [20] = Plaza  1
    // [21] = Plaza  2
    // [22] = Plaza  3
    // [23] = Plaza  4
    // [24] = Plaza  5
    // [25] = Plaza  6
    // [26] = Plaza Res

$areaList = 
    array (1=>
        "<b>Upstairs Tables", "<b>Upstairs Seats", "<b>Upstairs TV", "<b>Upstairs Computers", 
        "<b>Lounges SL", "<b>Lounges BL", "<b>Conference</b><br />Room 216", "<b>Conference</b><br />Room 218",
        "<b>Conference</b><br />Room 219", "<b>Conference</b><br />Room 220", "<b>Cash 204" , "<b>Cash 205", 
        "<b>Cash 207", "Downstairs Lobby", "<b>Downstairs Center", "<b>Downstairs Rec", 
        "<b>Downstairs Computers", "<b>Games  Bowling", "<b>Games  Billiards", "<b>Games  Arcade",
        "<b>Plaza 1", "<b>Plaza 2", "<b>Plaza 3", "<b>Plaza 4", "<b>Plaza 5", 
        "<b>Plaza 6", "<b>Plaza Res" 

    );  
    //array_unshift($areaList, "");
    //unset($areaList[0]);  
?>

<div id="add_content">                          
    <table class="listing" width="100%">
        <tr>
            <th width="25%">Area</th>
            <th width="5%">Count</th>
            <th width="40%">Comment</th>
            <th width="10%"></th>
        </tr>

        <?PHP
        $odd = 1;
        for ( $i = 1 ; $i < count($areaList) ; $i++ )
        {
            $odd=$odd+1;?>
           <form name="add" action="/directory/filename/" method="post" enctype="multipart/form-data">
            <tr <?PHP if($odd%2==1) echo "class=\"odd\"" ?>>
            <td style="text-align:center;">
            <?php echo $areaList[$i]; ?>
            <input type="hidden" name="data[TableName][area]" value="<?PHP echo $i;?>" />
            </td>
            <td>
            <?PHP 
            foreach ($upc as $uvalue) //$upc is an array from sql statement in Model.."SELECT area FROM table_name WHERE table_reports_id = ".$id." ORDER by area ASC"
            // there are 27 areas and it is displaying 27 counts for each Area instead of 1 count per area. I need to tell it to only grab the count for this area based on $i.
            {
                echo $html->input('Table/count'.$i, array('class'=>'inputbox','size'=>'3', 'value'=> $uvalue['table_name']['count'] ));

            } ?>
            </td> 
            <td width="25%"style="text-align:center;">
            <?php echo $html->input('Table/comments'.$i, array('size' => '50'), array('maxlength' => '60'));?></td>
            <td class="tdsubmitbutton" colspan="4" style="text-align:right">
            <?php echo $html->submit('Submit') ?></td>
            </tr>

         </form>
        <?PHP unset ($uvalue); }
            ?>
    </table>
    </div>
    ?>

解决方案是:数组
$upc
,索引为
$i
减1

<?PHP
    // areaList
    //  [0] = Upstairs Tables
    //  [1] = Upstairs Seats
    //  [2] = Upstairs TV
    //  [3] = Upstairs Computers
    //  [4] = Lounges SL
    //  [5] = Lounges BL
    //  [6] = Conference Room 216
    //  [7] = Conference Room 218
    //  [8] = Conference Room 219
    //  [9] = Conference Room 220
    // [10] = Cash 204
    // [11] = Cash 205
    // [12] = Cash 207
    // [13] = Downstairs Lobby
    // [14] = Downstairs Center
    // [15] = Downstairs Rec
    // [16] = Downstairs Computers
    // [17] = Games Bowling
    // [18] = Games Billiards
    // [19] = Games Arcade
    // [20] = Plaza  1
    // [21] = Plaza  2
    // [22] = Plaza  3
    // [23] = Plaza  4
    // [24] = Plaza  5
    // [25] = Plaza  6
    // [26] = Plaza Res

$areaList = 
    array (1=>
        "<b>Upstairs Tables", "<b>Upstairs Seats", "<b>Upstairs TV", "<b>Upstairs Computers", 
        "<b>Lounges SL", "<b>Lounges BL", "<b>Conference</b><br />Room 216", "<b>Conference</b><br />Room 218",
        "<b>Conference</b><br />Room 219", "<b>Conference</b><br />Room 220", "<b>Cash 204" , "<b>Cash 205", 
        "<b>Cash 207", "Downstairs Lobby", "<b>Downstairs Center", "<b>Downstairs Rec", 
        "<b>Downstairs Computers", "<b>Games  Bowling", "<b>Games  Billiards", "<b>Games  Arcade",
        "<b>Plaza 1", "<b>Plaza 2", "<b>Plaza 3", "<b>Plaza 4", "<b>Plaza 5", 
        "<b>Plaza 6", "<b>Plaza Res" 

    );  
    //array_unshift($areaList, "");
    //unset($areaList[0]);  
?>

<div id="add_content">                          
    <table class="listing" width="100%">
        <tr>
            <th width="25%">Area</th>
            <th width="5%">Count</th>
            <th width="40%">Comment</th>
            <th width="10%"></th>
        </tr>

        <?PHP
        $odd = 1;
        for ( $i = 1 ; $i < count($areaList) ; $i++ )
        {
            $odd=$odd+1;?>
           <form name="add" action="/directory/filename/" method="post" enctype="multipart/form-data">
            <tr <?PHP if($odd%2==1) echo "class=\"odd\"" ?>>
            <td style="text-align:center;">
            <?php echo $areaList[$i]; ?>
            <input type="hidden" name="data[TableName][area]" value="<?PHP echo $i;?>" />
            </td>
            <td>
            <?PHP 
            foreach ($upc as $uvalue) //$upc is an array from sql statement in Model.."SELECT area FROM table_name WHERE table_reports_id = ".$id." ORDER by area ASC"
            // there are 27 areas and it is displaying 27 counts for each Area instead of 1 count per area. I need to tell it to only grab the count for this area based on $i.
            {
                echo $html->input('Table/count'.$i, array('class'=>'inputbox','size'=>'3', 'value'=> $uvalue['table_name']['count'] ));

            } ?>
            </td> 
            <td width="25%"style="text-align:center;">
            <?php echo $html->input('Table/comments'.$i, array('size' => '50'), array('maxlength' => '60'));?></td>
            <td class="tdsubmitbutton" colspan="4" style="text-align:right">
            <?php echo $html->submit('Submit') ?></td>
            </tr>

         </form>
        <?PHP unset ($uvalue); }
            ?>
    </table>
    </div>
    ?>

我还需要学习如何正确提交代码块以及如何在事件发生后上传支持图片我还需要学习如何正确提交代码块以及如何在事件发生后上传支持图片'value'=>$uvalue[$I]['table_name']['count'];//返回未定义的偏移量$upc数组返回。。。。。。数组(27){[0]=>array(1){[“表名”]=>array(1){[“计数”]=>string(2)“17”}[1]=>array(1){[“表名”]=>array(1){[“计数”]=>string(2)“17”}[2]=>array(1){[“表名”]=>array(1){[“计数”=>string(1)“3”}[3]=>array(1){“表名”=>array(1){=>array(1){[“count”]=>string(2)“88”}[5]=>array(1){[“table_name”]=>array(1){[“count”]=>string(1)“6”}...etc'value'=>$uvalue[$i]['table_name']['count']];//返回未定义的偏移量$upc数组返回……数组(27){[0]=>array(1){[“table_name”=>array(1){[“count string”=>=>数组(1){[“计数”]=>字符串(2)“17”}[2]=>数组(1){[“表名”]=>数组(1){[“计数”]=>字符串(1)“3”}[3]=>数组(1){[“表名”]=>数组(1){[“计数”]=>字符串(2)“99”}[4]=>数组(1){[“表名”=>数组(1){“计数”=>字符串(2)”88}[5”=>表名”=>字符串(1){等