How Can I fillup bootstrap grid using foreach?
As I am trying to make bootstrap grid structure using foreach
two column and inside it's one row and two rows structure. Attached a screen shot for better to better view.
Note: Not issue with CSS but first three items are goes in grid as picture.
Counter is not taking col-md-4
and not sure where to use Counter increment counter++
? What if I want to show first three items using foreach
?
Any other way to workaround on this layout? Tried so far as below
<?php $counter = 0;
foreach($view->result as $result) {
<div id="hot-post" class="row hot-post">
<?php if( $counter == 0 || $counter % 3 == 0 ) { ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php if( $counter == 1 || $counter == 2 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
</php if ( $counter == 2)
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php counter++; ?>
</div> //closing row
<?php ?> //closing foreach
php for-loop foreach twitter-bootstrap-2 col
add a comment |
As I am trying to make bootstrap grid structure using foreach
two column and inside it's one row and two rows structure. Attached a screen shot for better to better view.
Note: Not issue with CSS but first three items are goes in grid as picture.
Counter is not taking col-md-4
and not sure where to use Counter increment counter++
? What if I want to show first three items using foreach
?
Any other way to workaround on this layout? Tried so far as below
<?php $counter = 0;
foreach($view->result as $result) {
<div id="hot-post" class="row hot-post">
<?php if( $counter == 0 || $counter % 3 == 0 ) { ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php if( $counter == 1 || $counter == 2 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
</php if ( $counter == 2)
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php counter++; ?>
</div> //closing row
<?php ?> //closing foreach
php for-loop foreach twitter-bootstrap-2 col
You may want to look at this to make your code easier to read when mixing PHP and HTML like you're doing here: php.net/manual/en/control-structures.alternative-syntax.php
– miken32
Nov 12 '18 at 21:25
add a comment |
As I am trying to make bootstrap grid structure using foreach
two column and inside it's one row and two rows structure. Attached a screen shot for better to better view.
Note: Not issue with CSS but first three items are goes in grid as picture.
Counter is not taking col-md-4
and not sure where to use Counter increment counter++
? What if I want to show first three items using foreach
?
Any other way to workaround on this layout? Tried so far as below
<?php $counter = 0;
foreach($view->result as $result) {
<div id="hot-post" class="row hot-post">
<?php if( $counter == 0 || $counter % 3 == 0 ) { ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php if( $counter == 1 || $counter == 2 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
</php if ( $counter == 2)
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php counter++; ?>
</div> //closing row
<?php ?> //closing foreach
php for-loop foreach twitter-bootstrap-2 col
As I am trying to make bootstrap grid structure using foreach
two column and inside it's one row and two rows structure. Attached a screen shot for better to better view.
Note: Not issue with CSS but first three items are goes in grid as picture.
Counter is not taking col-md-4
and not sure where to use Counter increment counter++
? What if I want to show first three items using foreach
?
Any other way to workaround on this layout? Tried so far as below
<?php $counter = 0;
foreach($view->result as $result) {
<div id="hot-post" class="row hot-post">
<?php if( $counter == 0 || $counter % 3 == 0 ) { ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php if( $counter == 1 || $counter == 2 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
</php if ( $counter == 2)
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php counter++; ?>
</div> //closing row
<?php ?> //closing foreach
php for-loop foreach twitter-bootstrap-2 col
php for-loop foreach twitter-bootstrap-2 col
asked Nov 12 '18 at 20:06
Nisarg
1,33931123
1,33931123
You may want to look at this to make your code easier to read when mixing PHP and HTML like you're doing here: php.net/manual/en/control-structures.alternative-syntax.php
– miken32
Nov 12 '18 at 21:25
add a comment |
You may want to look at this to make your code easier to read when mixing PHP and HTML like you're doing here: php.net/manual/en/control-structures.alternative-syntax.php
– miken32
Nov 12 '18 at 21:25
You may want to look at this to make your code easier to read when mixing PHP and HTML like you're doing here: php.net/manual/en/control-structures.alternative-syntax.php
– miken32
Nov 12 '18 at 21:25
You may want to look at this to make your code easier to read when mixing PHP and HTML like you're doing here: php.net/manual/en/control-structures.alternative-syntax.php
– miken32
Nov 12 '18 at 21:25
add a comment |
1 Answer
1
active
oldest
votes
There are couple of syntax errors in your code, such as:
- Opening and closing braces are not in sync i.e.
foreach
loop andif
block(s) are not closed properly counter++;
should be$counter++;
Plus, there are few logical errors as well. Change your code in the following way,
<?php
$counter = 0;
foreach($view->result as $result) $counter % 3 == 0 ) ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php ?>
<?php if( $counter != 0 && $counter % 3 != 0 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter % 3 == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
<?php ?>
<?php if ( $counter % 3 == 2) ?>
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php ?>
</div>
<?php
++$counter;
?>
Great! that works. due to copy-paste forgot to add Opening and closing braces but the main issue iscounter++
and if condition
– Nisarg
Nov 12 '18 at 20:54
1
@Nisarg, Glad I could help! :-) I don't think the suggested edit is necessary, given the current problem at hand.
– Rajdeep Paul
Nov 12 '18 at 21:01
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269345%2fhow-can-i-fillup-bootstrap-grid-using-foreach%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are couple of syntax errors in your code, such as:
- Opening and closing braces are not in sync i.e.
foreach
loop andif
block(s) are not closed properly counter++;
should be$counter++;
Plus, there are few logical errors as well. Change your code in the following way,
<?php
$counter = 0;
foreach($view->result as $result) $counter % 3 == 0 ) ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php ?>
<?php if( $counter != 0 && $counter % 3 != 0 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter % 3 == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
<?php ?>
<?php if ( $counter % 3 == 2) ?>
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php ?>
</div>
<?php
++$counter;
?>
Great! that works. due to copy-paste forgot to add Opening and closing braces but the main issue iscounter++
and if condition
– Nisarg
Nov 12 '18 at 20:54
1
@Nisarg, Glad I could help! :-) I don't think the suggested edit is necessary, given the current problem at hand.
– Rajdeep Paul
Nov 12 '18 at 21:01
add a comment |
There are couple of syntax errors in your code, such as:
- Opening and closing braces are not in sync i.e.
foreach
loop andif
block(s) are not closed properly counter++;
should be$counter++;
Plus, there are few logical errors as well. Change your code in the following way,
<?php
$counter = 0;
foreach($view->result as $result) $counter % 3 == 0 ) ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php ?>
<?php if( $counter != 0 && $counter % 3 != 0 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter % 3 == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
<?php ?>
<?php if ( $counter % 3 == 2) ?>
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php ?>
</div>
<?php
++$counter;
?>
Great! that works. due to copy-paste forgot to add Opening and closing braces but the main issue iscounter++
and if condition
– Nisarg
Nov 12 '18 at 20:54
1
@Nisarg, Glad I could help! :-) I don't think the suggested edit is necessary, given the current problem at hand.
– Rajdeep Paul
Nov 12 '18 at 21:01
add a comment |
There are couple of syntax errors in your code, such as:
- Opening and closing braces are not in sync i.e.
foreach
loop andif
block(s) are not closed properly counter++;
should be$counter++;
Plus, there are few logical errors as well. Change your code in the following way,
<?php
$counter = 0;
foreach($view->result as $result) $counter % 3 == 0 ) ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php ?>
<?php if( $counter != 0 && $counter % 3 != 0 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter % 3 == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
<?php ?>
<?php if ( $counter % 3 == 2) ?>
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php ?>
</div>
<?php
++$counter;
?>
There are couple of syntax errors in your code, such as:
- Opening and closing braces are not in sync i.e.
foreach
loop andif
block(s) are not closed properly counter++;
should be$counter++;
Plus, there are few logical errors as well. Change your code in the following way,
<?php
$counter = 0;
foreach($view->result as $result) $counter % 3 == 0 ) ?>
<div class="col-md-8 hot-post-left">
<div class="post post-thumb">
// first element common body
</div>
</div>
<?php ?>
<?php if( $counter != 0 && $counter % 3 != 0 ) ?>
<div class="col-md-4 hot-post-right">
<?php if( $counter % 3 == 1) ?>
<div class="post post-thumb">
// second element common body
</div>
<?php ?>
<?php if ( $counter % 3 == 2) ?>
<div class="post post-thumb">
// third element common body
</div>
</div>
<?php ?>
</div>
<?php
++$counter;
?>
answered Nov 12 '18 at 20:44
Rajdeep Paul
15.9k31229
15.9k31229
Great! that works. due to copy-paste forgot to add Opening and closing braces but the main issue iscounter++
and if condition
– Nisarg
Nov 12 '18 at 20:54
1
@Nisarg, Glad I could help! :-) I don't think the suggested edit is necessary, given the current problem at hand.
– Rajdeep Paul
Nov 12 '18 at 21:01
add a comment |
Great! that works. due to copy-paste forgot to add Opening and closing braces but the main issue iscounter++
and if condition
– Nisarg
Nov 12 '18 at 20:54
1
@Nisarg, Glad I could help! :-) I don't think the suggested edit is necessary, given the current problem at hand.
– Rajdeep Paul
Nov 12 '18 at 21:01
Great! that works. due to copy-paste forgot to add Opening and closing braces but the main issue is
counter++
and if condition– Nisarg
Nov 12 '18 at 20:54
Great! that works. due to copy-paste forgot to add Opening and closing braces but the main issue is
counter++
and if condition– Nisarg
Nov 12 '18 at 20:54
1
1
@Nisarg, Glad I could help! :-) I don't think the suggested edit is necessary, given the current problem at hand.
– Rajdeep Paul
Nov 12 '18 at 21:01
@Nisarg, Glad I could help! :-) I don't think the suggested edit is necessary, given the current problem at hand.
– Rajdeep Paul
Nov 12 '18 at 21:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269345%2fhow-can-i-fillup-bootstrap-grid-using-foreach%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You may want to look at this to make your code easier to read when mixing PHP and HTML like you're doing here: php.net/manual/en/control-structures.alternative-syntax.php
– miken32
Nov 12 '18 at 21:25