我需要帮助,我无法比较来自数据库的循环值。在数据库中我有4行所有这些都显示在一个表中,我有一个包含1,2,4的数组值。我如何比较它,所以我只能显示check属性值为1, 2,4。
数据库表
roles | level
---------------------
bod | 1
event | 2
htab | 3
tab | 4
PHP代码
$array_soc = array = (1,2,4); //<-- This is the array that i need to compare
$sql10 = mysql_query("SELECT * from tbl_event_roles");
$count = 1;
$counts = 0;
$array_level = [];
while($soc_sqll0 = mysql_fetch_assoc($sql10)){
$output .= '<tr>';
$output .= '<td>'.($soc_sqll0['level'] ==1 ? '
<div style="float:left;">'.$soc_sqll0['roles'].'</div>
<div style="float:right; font-size:15px; "><i> (Recommended to have) <i></div> ' : ''.$soc_sqll0['roles'].'').'</td>';
$output .= '<td style="width:50px;">
<input type="checkbox" value="'.$count.'"
'.( $array_level[$counts] == $array_soc[$counts] ? 'checked' : '').' //<-- Here is the problem, i'm trying to compare but i got an error undefined offset
id="check_boxs'.$count.'" name="roles_checked_userStaff[]"></td>';
$output .= '</tr>';
array_push($array_level, $count);
$count++;
$counts++;
}
答案 0 :(得分:0)
您的"#!/bin/bash\n",
"cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php\n",
"sed -i \"s/'database_name_here'/'",
{
"Ref": "DBName"
},
"'/g\" wp-config.php\n",
"sed -i \"s/'username_here'/'",
{
"Ref": "DBUser"
},
"'/g\" wp-config.php\n",
"sed -i \"s/'password_here'/'",
{
"Ref": "DBPassword"
},
"'/g\" wp-config.php\n",
"sed -i \"s/'localhost'/'",
{
"Fn::GetAtt": [
"DBInstance", "Endpoint.Address"
]
},
"'/g\" wp-config.php\n"
在循环中有值之前已被使用。
要么初始化$array_level
,要么将$array_level[0] = ...
放在array_push($array_level, $count);
之前。
答案 1 :(得分:0)
查看这段代码,此错误似乎是由于数组$array_soc
等于array = (1,2,4);
且$counts
大于2而导致的。
要使用$array_soc[$counts]
,$counts
需要介于0和2之间(数组的位置:array = (1,2,4);
)。否则,将发出错误未定义的偏移量。