Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I'm using x-editable for bootstrap, which is awsome for me.

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:

    $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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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']);
}
share|improve this answer
 
Yup, that did the trick. Thanks! –  Matt Apr 10 '13 at 17:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.