while Inside the variable

Asked

Viewed 37 times

1

I’m creating a search system where the user will only post the month and year they want to search. but I’m not getting the code is as follows

$output='<h2 class="text-center mb-4" style="color:red">Elementos</h2>
        <div class="table-responsive">          
            <table class="table">
                <thead>
                    <tr class="jumbotron">
                        <th>Nº Interno</th>
                        <th>Nome</th>
                        <th>SV</th>
                    </tr>
                </thead>
                '.do{.' 
                    <tbody style="border-bottom:2px solid red;">
                        <td>'.$row_elementos['N Interno'].'</td>
                        <td>'.$row_elementos['Nome'].'</td>
                        <td>'.$total.'</td>
                    </tbody>'.
                }while ($row_elementos = mysql_fetch_assoc($elementos)).'
            </table>
        </div>';

Then print the base of the search done below with the following code

<?php print("$output");?>

the errors are in {do(syntax error, Unexpected 'do'(T_DO))} and {while(syntax error, Unexpected '}' }. How should I correct my mistakes?

  • Close the string first, then do a normal while.

  • how so? while is only done on that site

  • He meant to close the string there on the thead and do the normal while

  • but this is done after a search

2 answers

2


Try concatenating by pieces not mixing everything into a cake. Example:

$output='<h2 class="text-center mb-4" style="color:red">Elementos</h2>
    <div class="table-responsive">          
        <table class="table">
            <thead>
                <tr class="jumbotron">
                    <th>Nº Interno</th>
                    <th>Nome</th>
                    <th>SV</th>
                </tr>
            </thead><tbody style="border-bottom:2px solid red;">';
            do{ 
                $output .= '<td>'.$row_elementos['N Interno'].'</td>
                    <td>'.$row_elementos['Nome'].'</td>
                    <td>'.$total.'</td>';
            }while ($row_elementos = mysql_fetch_assoc($elementos));
$output .= '</tbody></table></div>';

2

First close the string, it is not possible to concatenate it with a repeat loop. Use a while whether to use the do-while in the case of the empty return query some Undefined index will be generated because they do not exist and because the check is done only at the end of the loop and not at the beginning.

$output='<h2 class="text-center mb-4" style="color:red">Elementos</h2>
        <div class="table-responsive">          
            <table class="table">
                <thead>
                    <tr class="jumbotron">
                        <th>Nº Interno</th>
                        <th>Nome</th>
                        <th>SV</th>
                    </tr>
                </thead>';

                while ($row_elementos = mysql_fetch_assoc($elementos)){
                    $output .= '<tbody style="border-bottom:2px solid red;">
                        <td>'.$row_elementos['N Interno'].'</td>
                        <td>'.$row_elementos['Nome'].'</td>
                        <td>'.$total.'</td>
                    </tbody>';
                }   


            $output.= '</table></div>';
  • is functional but I did not appear the first element

  • @Adelinovasconcelos is to display all the records. You use somewhere else $row_elementos or fills it manually?

  • What do you mean? I didn’t notice

Browser other questions tagged

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