blmg2009 Posted June 13, 2015 Share Posted June 13, 2015 I'm currently learning PHP so I'm a noob; I'm looking at looping form 1 to 64 and on each loop echoing out html to build a table. This I can do easily. However I also want to add in some PHP in the output of each loop; However I'm not sure how I would do this correctly. for ($i = 1; $i <= 64; $i++) { echo <div class="col-xs-3 team_box top-team-border"><?php echo $results->get_team('64', '<?php echo $i; ?>', 'A', 'main'); ?> <span class="badge"><?php echo $results->get_score('64', '<?php echo $i; ?>', 'A', 'main'); ?></span></div> } Quote Link to comment https://forums.phpfreaks.com/topic/296795-php-loop-to-echo-html-and-some-php-code/ Share on other sites More sharing options...
QuickOldCar Posted June 13, 2015 Share Posted June 13, 2015 Is a few ways actually, you have to echo html in quotes if within php or break in and out of php using <?php ?> tags <?php for ($i = 1; $i <= 64; $i++) { ?> <div class="col-xs-3 team_box top-team-border"><?php echo $results->get_team('64', '<?php echo $i; ?>', 'A', 'main'); ?> <span class="badge"><?php echo $results->get_score('64', '<?php echo $i; ?>', 'A', 'main'); ?></span></div> <?php } ?> or <?php for ($i = 1; $i <= 64; $i++) { echo "<div class='col-xs-3 team_box top-team-border'>".$results->get_team('64', '".$i."', 'A', 'main')."<span class='badge'>".$results->get_score('64', '".$i."', 'A', 'main')."</span></div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/296795-php-loop-to-echo-html-and-some-php-code/#findComment-1513804 Share on other sites More sharing options...
Ch0cu3r Posted June 13, 2015 Share Posted June 13, 2015 (edited) You dont use PHP tags within a echo statement, You need to use the concatenation operator when outputting multiple things within your string for ($i = 1; $i <= 64; $i++) { echo ' <div class="col-xs-3 team_box top-team-border">' . $results->get_team('64', $i, 'A', 'main') . '<span class="badge">' . $results->get_score('64', $i, 'A', 'main') . '</span> </div>'; } // Or assign the team and score to variables and use them in your string for ($i = 1; $i <= 64; $i++) { $team = $results->get_team('64', $i, 'A', 'main'); $score = $results->get_score('64', $i, 'A', 'main'); echo " <div class=\"col-xs-3 team_box top-team-border\"> $team <span class=\"badge\">$score</span> </div>"; } Edited June 13, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/296795-php-loop-to-echo-html-and-some-php-code/#findComment-1513806 Share on other sites More sharing options...
QuickOldCar Posted June 13, 2015 Share Posted June 13, 2015 If are just learning may want to check out the php tutorial Quote Link to comment https://forums.phpfreaks.com/topic/296795-php-loop-to-echo-html-and-some-php-code/#findComment-1513809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.