Concatenate WHILE

Asked

Viewed 195 times

-3

How can I concatenate a while to put into an array. How to make this part of code work?

$nestedData[] = $row["nomerota"];

                $tr="<select size='1'>";
                $tr.= while ($row = mysqli_fetch_array($resultado)) 
                {
                <option value='$row['nome'];'>$row['nome'];</option>                         
                }
                $tr.="</select>";

$nestedData[] = $tr;

my problem is here:

$tr.= while ($row = mysqli_fetch_array($resultado)) 
            {
            <option value='$row['nome'];'>$row['nome'];</option>                         
            }
  • 3

    Instead of $tr.= while do $tr.= "<option value='".$row['nome']."'>".$row['nome']."</option>";

  • You have unconnected code &#xA; <option value='$row['nome'];'>$row['nome'];</option> &#xA;

  • Pq you do not loop and concatenate the string?

1 answer

0

I believe you want something like this:

$nestedData[] = $row["nomerota"];
$tr="<select size='1'>";
while ($row = mysqli_fetch_array($resultado)) {
    $tr.= "<option value='$row['nome'];'>$row['nome'];</option>"                         
}
$tr.="</select>";
$nestedData[] = $tr;

You must not concatenate the while and yes the text and variables that are inside

Browser other questions tagged

You are not signed in. Login or sign up in order to post.