Jump to content

While loop inside a Foreach


MarcelloPato

Recommended Posts

Hi everyone, greetings from Brazil.

I am an average php coder, much more a designer than an programer, and i am in a looper trouble..

Can anyone try to help me?

 

Here is my code:

 

            <table border="1">
            <tr>
                <?php //pega cada uma das operadoras do campo operadoras
                $operadoras = $opers_trazOperadoras ;
                $logos = explode(",",$operadoras);
                $x = 0 ;
                foreach ($logos as $v)
                {
                    mysql_select_db($database_webroker, $webroker);
                    $query_trazLogoOperadora = "SELECT * FROM tb_operadora WHERE tb_operadora.id_operadora = " . $v ;
                    $trazLogoOperadora = mysql_query($query_trazLogoOperadora, $webroker) or die(mysql_error());
                    $row_trazLogoOperadora = mysql_fetch_assoc($trazLogoOperadora);
                    $totalRows_trazLogoOperadora = mysql_num_rows($trazLogoOperadora);
                ?>
                        <td><img src="http://www.we-broker.com.br/admin/imagens_upload/<?php echo $row_trazLogoOperadora['logo']; ?>">
                        <?php do { ?>
                            <?php
                            } while ($x++ < 4); {
                            echo $x ;?>
                                </td></tr><tr>
                            <?php } $x = 0 ;
                        }
                  ?>
            </table>

 

The URL for this code is: http://valsegs.we-broker.com.br/operadorasPATO.php

Tks!

Link to comment
https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/
Share on other sites

You didn't ask a question!!

 

This code:

 

<?php do { ?>
<?php
 } while ($x++ < 4); {
echo $x ;?>
 </td></tr><tr>
  <?php } $x = 0 ;
  }

is ridiculous.

 

Try this - note that I turned on error checking so you can see what error you have:

 

<?php
session_start();
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
//
do
{
}
while ($x++ < 4);
{
 echo $x;
 echo "</td></tr><tr>";
}
$x = 0 ;
}

You don't need all those php on and php off tags.

You don't need a do statement with no contents

You don't put a semi at the end of the while line - it leaves you with no contents again.

 

I think you want:

 

<?php
session_start();
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
//
while ($x = 0;$x < 4; $x++)
{
 echo "<tr><td>$x</td></tr>";
}

This will give you a set of 4 table rows with one cell counting from 0 to 3.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.