Jump to content
MarcelloPato

While loop inside a Foreach

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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

 

is ridiculous

Not to mention all mysql_* functions inside the foreach construct :)

Share this post


Link to post
Share on other sites

@ginerjm

 

 

 

while ($x = 0;$x < 4; $x++)

 

That's weird while() syntax you're using there

Edited by Barand

Share this post


Link to post
Share on other sites

oops - meant to say 'for'.  Got distracted by the op's bad code.

Share this post


Link to post
Share on other sites

Well, like I said, I am more designer than coder, so I thank you all for the answers.

The question that i didn´t aks is: What i am doing wrong, because it is not working.

 

Now, i´ll try all your suggestions and let´s see what happens!

Share this post


Link to post
Share on other sites

Not to mention all mysql_* functions inside the foreach construct :)

THat´s because I exploded a comma separeted filed with a loto of id´s so I can query for the logos on other table.

Isn´t it right?

Share this post


Link to post
Share on other sites

AS I SAID IN MY FIRST POST - you didn't tell us what was wrong.  You didn't ask us to fix anything.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.