MarcelloPato Posted September 16, 2014 Share Posted September 16, 2014 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 More sharing options...
ginerjm Posted September 16, 2014 Share Posted September 16, 2014 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. Link to comment https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/#findComment-1491316 Share on other sites More sharing options...
jazzman1 Posted September 16, 2014 Share Posted September 16, 2014 is ridiculous Not to mention all mysql_* functions inside the foreach construct Link to comment https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/#findComment-1491317 Share on other sites More sharing options...
Barand Posted September 16, 2014 Share Posted September 16, 2014 @ginerjm while ($x = 0;$x < 4; $x++) That's weird while() syntax you're using there Link to comment https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/#findComment-1491326 Share on other sites More sharing options...
ginerjm Posted September 16, 2014 Share Posted September 16, 2014 oops - meant to say 'for'. Got distracted by the op's bad code. Link to comment https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/#findComment-1491332 Share on other sites More sharing options...
MarcelloPato Posted September 17, 2014 Author Share Posted September 17, 2014 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! Link to comment https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/#findComment-1491354 Share on other sites More sharing options...
MarcelloPato Posted September 17, 2014 Author Share Posted September 17, 2014 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? Link to comment https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/#findComment-1491356 Share on other sites More sharing options...
ginerjm Posted September 17, 2014 Share Posted September 17, 2014 AS I SAID IN MY FIRST POST - you didn't tell us what was wrong. You didn't ask us to fix anything. Link to comment https://forums.phpfreaks.com/topic/291108-while-loop-inside-a-foreach/#findComment-1491361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.