$data = Array (), if (!empty ($_post[' field_id ')) {foreach ($_post[' field_id '] as $k = = $v) {$data [] = Array (' field_id ' = > $v, ' Choice ' = isset ($_post[' Choice '] [$k])? $_post[' Choice ' [$k]: ', ' uid ' = + $_post[' uid '], ' game_id ' = ' $_post[' game_id '], ' server_id ' = $_post[' server _id ']); } }
This is where I loop the formatting, the following is the output of the array data
Array ( [0] = = Array ( [field_id] = 1 [Choice] = 0 [UID] = 110000110 [game_id] =& Gt 2 [server_id] + 2 ) [1] = = Array ( [field_id] = 2 [choice] + 0 [UID] = > 110000110 [game_id] = 2 [server_id] + 2 ) [2] = = Array ( [field_id] = > 3 [Choice] = 1 [uid] = 110000110 [game_id] = 2 [server_id] + 2 ))
When choiece equals null when [choice] + does not add to the data array when there is no value how to implement it?
Reply to discussion (solution)
[1] = = Array
(
[FIELD_ID] = 2
[Choice] =
[UID] = 110000110
[GAME_ID] = 2
[SERVER_ID] = 2
)
In situations like this, 0 and 1 are valued.
The data in your sample does not have [choice] =
If so, do you want to choice the item or the whole group?
Do you have a $_post[' choice ' loop, which is not easier than a loop of $_post[' field_id ')?
The data in your sample does not have [choice] =
If so, do you want to choice the item or the whole group?
Do you have a $_post[' choice ' loop, which is not easier than a loop of $_post[' field_id ')?
Array
(
[0] = = Array
(
[FIELD_ID] = 1
[Choice] = 0
[UID] = 110000110
[GAME_ID] = 2
[SERVER_ID] = 2
)
[1] = = Array
(
[FIELD_ID] = 2
[Choice] =
[UID] = 110000110
[GAME_ID] = 2
[SERVER_ID] = 2
)
[2] = = Array
(
[FIELD_ID] = 3
[Choice] =
[UID] = 110000110
[GAME_ID] = 2
[SERVER_ID] = 2
)
)
Probably is such an effect, does not have the value not to have, shows like this
Array
(
[0] = = Array
(
[FIELD_ID] = 1
[Choice] = 0
[UID] = 110000110
[GAME_ID] = 2
[SERVER_ID] = 2
)
)
Only the choice has no value, the entire array is not.
$data = Array (), if (!empty ($_post[' field_id ')) { foreach ($_post[' Choice '] as $k = + $v) { if ($v = = ") continu e; $data [] = Array ( ' field_id ' = $_post[' field_id '] [$k], ' choice ' = $_post[' Choice ' [$k], ' uid ' = > $_post[' uid '], ' game_id ' = ' $_post[' game_id '], ' server_id ' = $_post[' server_id '] ) ; }
$data = Array (), if (!empty ($_post[' field_id ')) { foreach ($_post[' Choice '] as $k = + $v) { if ($v = = ") Conti Nue; $data [] = Array ( ' field_id ' = $_post[' field_id '] [$k], ' choice ' = $_post[' Choice ' [$k], ' uid ' = > $_post[' uid '], ' game_id ' = ' $_post[' game_id '], ' server_id ' = $_post[' server_id '] ); }
Thank you moderator, but I use the following batch add, if you have selected the will prompt failure, TP inside AddAll How to determine whether it has been added?
$Choice =d (' Myselect '),//$choices = $Choice->addall ($data), if ($Choice->addall ($data)) {$back [' status ']= ' Success '; $back [' msg ']= ' your bets have been successful! '; $back [' url ']= ' game '; $this->back ($back); }else{$back [' Status ']= ' error '; $back [' msg ']= ' bet failed! Do not repeat the bet Oh! '; $back [' url ']= ' game '; $this->back ($back); exit;}}
if ($Choice->addall ($data, Array (), True)) {} Look at the MoD default is False, changing to true will always change the value of the database, it makes no sense.
if ($Choice->addall ($data, Array (), false)) {} How can you tell if the database is already in existence, and what is the best way for you predecessors?