So I'm using x-editable for bootstrap, which is awsome for me.
所以我使用x-editable进行引导,这对我来说很棒。
With that, to return a menu for selection one needs to return an array as such to make it work:
有了它,要返回一个选择菜单,需要返回一个数组,使其工作:
$arr = array(
array('value' => 'Male', 'text' => 'Male'),
array('value' => 'Female', 'text' => 'Female'),
);
It's fine if you have to write it, but now I need to make this array from database output.
如果你必须写它,这很好,但现在我需要从数据库输出中创建这个数组。
So for instance if I run a "while($row" loop, how is the output going to be an array like that. This is what I'm trying, but oviously failing at cause this is not working:
因此,例如,如果我运行“while($ row”循环,输出将如何变成这样的数组。这就是我正在尝试的,但是由于这个原因而无法正常运行:
$query = 'SELECT id,app_name FROM apps';
$result = mysql_query($query) or bomb($s,509,addslashes($query),addslashes(mysql_error()));
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)) {
$arr .= Array(
Array('value' => $row['id'], 'text' => $row['app_name']),
);
}
}
It's probably a silly question, so thanks in advanced.
这可能是一个愚蠢的问题,所以感谢先进。
1 个解决方案
#1
1
Arrays can't be concatenated like strings. Try something like this:
数组不能像字符串一样连接。尝试这样的事情:
while($row = mysql_fetch_assoc($result)) {
$arr[]=Array('value' => $row['id'], 'text' => $row['app_name']);
}
#1
1
Arrays can't be concatenated like strings. Try something like this:
数组不能像字符串一样连接。尝试这样的事情:
while($row = mysql_fetch_assoc($result)) {
$arr[]=Array('value' => $row['id'], 'text' => $row['app_name']);
}