[英]How do I select all categories per product and returning this in one row per product?
[英]How do I fix nested loop because it displays all values for each row instead of one value per row?
<?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] 這樣的值
此外,如果那是您真正的 sql 語句,您應該始終用 '' 括起參數並確保轉義所有輸入。
解決方案是:數組$upc
,索引為$i
減 1。
echo $html->input('Table/count'.$i, array('class'=>'inputbox','size'=>'3', 'value'=> $upc[$i-1]['table_name']['count'] ));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.