Bootstrap Layout when using PHP Foreach - php

I am currently displaying content from my database using a foreach loop within a boostrap panel. However the layout is not behaving as I expected it too, I have tried resolving this using breaks which had fixed the layout from being worse than it is at the present. However it is still off if you take a look at the image below :-
In addition to this I also have bootstrap dropdown menu's that are not working at all embedded within a div.
This is my code -
<div class="parabox">
<!-- Collect the nav links, forms, and other content for toggling -->
<!-- Search -->
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search For Comics">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<strong><p class="navbar-text">Sort Comics By : </p></strong>
<ul class="nav navbar-nav">
<li class="dropdown">
Order Comics<span class="caret"></span>
<ul class="dropdown-menu">
<li>Ascending Order</li>
<li>Descending Order</li>
<li>Numerical Order</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-left">
<li class="dropdown">
Universe<span class="caret"></span>
<ul class="dropdown-menu">
<li>Dark Horse Comics</li>
<li>DC</li>
<li>IDW</li>
<li>Image</li>
<li>Marvel</li>
<li>Valiant</li>
</li>
</ul>
</div>
</div>
</br>
<!-- Start of Col Div -->
<div class="col-md-12">
<!--/.Panel for Comics -->
<!-- Count for Comics -->
<?php
if(count($comics)){
?>
</br>
<div class="panel panel-default">
<div class="panel-heading panel-heading-green">
<h3 class="panel-title">My Comics</h3>
</div>
<div class="panel-body">
<div class="row">
<!--/.row1 -->
<!-- Display each comic by id -->
<?php foreach($comics as $list): ?>
</br>
<div class="col-md-3 comic">
<a href="#">
<?= ($list['image'] <> " " ? "<img style='max-width:200px; max-height:250px;' src='Images/{$list['image']}'/>" : "") ?>
</a>
<div class="comic-title">
<?= ($list['name'] <> "" ? $list['name'] : "") ?> #<?= ($list['issue'] <> "" ? $list['issue'] : "") ?>
</div>
<div class="comic-add">
</div>
</div>
<!-- End of Foreach Statement for Comics -->
<?php endforeach; ?>
<!-- Else show this message if user has no entries -->
<?php
}else {
?>
<p><b>You haven't posted any comic yet!</b></p>
<?php } ?>
</div>
</div>
</div>
<!--/.row1-collapse -->
</div>
<!-- /.container -->
</div>
I am using MVC format which is why the code may seem short or missing pieces which is in header and footers within my template part of my application. Any ideas on what I can do to sort the layout out and get the dropdown menu's to work as they do seem a little related ?

As far as I know, bootstrap requires you to always have a markup like:
<div class="container">
<div class="row">
<div class="col-*">…</div>
<!-- many more cols -->
</div>
</div>
So this:
container
row
col
col
col
row
…
structure should always be give, whereby this structure can be nested.
This way the layout has all the negative margin magic applied
UPDATE
According to the posted image I guess that the resulting markup is corrupted (if the »container > row > col« structure exists). I recommend to have a a look at the browser console and compare the resulting dom tree with the expected. It is also very helpful to search the page source, in Firefox corrupted elements (missing closing tag, wrong attributes etc) are shown in red, so this helps to find the bug.

*Create a wrapper div to hold the image, title etc. Then for that div add a css with the style as display:inline-block; So if it is not able to accomodate with in the view in browser, it will get automatically wrapped into the next line. Follow this example see teh working sample code created by some one: http://jsfiddle.net/ajruk60t/3/*

You must break your line after the number of columns your row can contain. For instance, if you use col-3, then you must not define more than 4 columns. At this point, you recreate a row and carry on.
<div class="row">
<?php
$i = 1;
foreach($comics as $list) { ?>
<div class="col-md-3">
...
</div>
<?php
if ($i % 4 == 0) {
?></div><div class="row"><?php
}
$i++;
?>
<?php } ?>
</div>
Alternatively, you can create the same effect adding manual breakpoints rather than recreating a row. I have not tried this solution myself, but read it here:
<div class="clearfix visible-md-block"></div>

Thank you for your help it steered me to the answer which was the foreach loop had to start after the break.
<?php require('template/header.phtml') ?>
<div class="container">
<div class="row">
<!-- Start of Col Div -->
<div class="col-md-12">
<!--/.Panel for Comics -->
<!-- Count for Comics -->
<?php
if(count($comics)){
?>
</br>
<div class="panel panel-default">
<div class="panel-heading panel-heading-green"><h3 class="panel-title">My Comics</h3></div><!-- End of Panel Heading -->
<div class="panel-body">
<div class="row">
<!--/.row1 -->
<!-- Display each comic by id -->
</br> <?php foreach($comics as $list): ?>
<div class="col-md-3 comic">
<a href="#">
<?= ($list['image'] <> " " ? "<img style='max-width:200px; max-height:250px;' src='Images/{$list['image']}'/>" : "") ?>
</a>
<div class="comic-title">
<?= ($list['name'] <> "" ? $list['name'] : "") ?> #<?= ($list['issue'] <> "" ? $list['issue'] : "") ?>
</div>
<div class="comic-add">
</div>
</div> <!-- End of Col-MD-3 Comic -->
<!-- End of Foreach Statement for Comics -->
<?php endforeach; ?>
<!-- Else show this message if user has no entries -->
<?php
}else {
?>
<p><b>You haven't posted any comic yet!</b></p>
<?php } ?>
</div><!-- end of row -->
</div> <!-- end of panel body -->
</div> <!-- end of panel panel-default -->
<!--/.row1-collapse -->
</div> <!-- end of col-md-12 -->
</div> <!-- End of Row -->
</div> <!-- /.container -->
<?php require('template/footer.phtml') ?>

Related

joomla 4 Blog category is not balanced correctly

I created a blog category from the menu. In Joomla 4 -> In Blog Layout -> Columns ، I can give a value to the column, but if we increase the value by one, the displayed contents are not balanced. And the "" did not close properly. After a general search, I realized that the contents are arranged as follows :
HTML :
<div class="blog-items">
<div class="blog-item">
<div class="content">1</div>
<div class="blog-item">
<div class="content">2</div>
</div>
<div class="blog-item">
<div class="content">3</div>
<div class="blog-item">
<div class="content">4</div>
<div class="blog-item">
<div class="content">5</div>
</div>
<div class="blog-item">
<div class="content">6</div>
</div>
<div class="blog-item">
<div class="content">7</div>
</div>
</div>
</div>
</div>
</div>
HTML The right way to be :
<div class="blog-items">
<div class="blog-item"><div class="content">1</div></div>
<div class="blog-item"><div class="content">2</div></div>
<div class="blog-item"><div class="content">3</div></div>
<div class="blog-item"><div class="content">4</div></div>
<div class="blog-item"><div class="content">5</div></div>
<div class="blog-item"><div class="content">6</div></div>
<div class="blog-item"><div class="content">7</div></div>
</div>
Note: When I disable "loadTemplate", the loop is displayed correctly and the divisions are closed correctly.
I also checked the information inside the "$this->loadTemplate('item')" but found no problem.
PHP :
<div class="blog-items">
<?php foreach ($this->intro_items as $key => &$item) : ?>
<div class="blog-item">
<?php
$this->item = & $item;
echo $this->loadTemplate('item'); //Included <div class="content">value</div>
?>
</div>
<?php endforeach; ?>
</div>
it's true,fixed.
All content had a tag before page break,
You cannot insert it inside a div. The closing tag will be missing. Close the tag before inserting Read More.
Little did I know that using before page break can be so destructive, and I've been looking for problems with PHP code for about a week now.

PHP (MySQL) Script doesn't read anything else once I add 'echo' and take something from table

I have a problem,
When I tried to list all users, to get their username/and others script didn't continue to read anything, it has stopped just after my echo input.
So when I put echo to get user's info it reads that input but it doesn't read anything after. See bellow there is a echo called 'userEmail' and it reads it with no problems but it doesn't go after signature. Now I have checked any everything works when i put it on a plain page but for some reason it stop readsing here. I'm a newbie in this PHP so yeah. :)
<?php
$query = mysql_query("SELECT userEmail FROM users");
while($userRow= mysql_fetch_array($query)){
echo '<div class="col-md-4">
<!-- Widget: user widget style 1 -->
<div class="box box-widget widget-user">
<div class="widget-user-header bg-blue" style="background-color: center center;">
</div>
<div class="widget-user-image">
<img alt="User Avatar" class="img-circle" src="//">
</div>
<div class="box-footer">
<div class="row">
<div class="col-sm-4 border-right">
<div class="description-block">
</div>
<!-- /.description-block -->
</div>
<!-- /.col -->
<div class="col-sm-4 border-right">
<div class="description-block">
<h5 class="description-header">'.$userRow['userEmail'];'</h5>
<h5 class="description-text">'.$userRow['userSignature'];'</h5>
</div>
<!-- /.description-block -->
</div>
<!-- /.col -->
<div class="col-sm-4">
<div class="description-block"></div>
<!-- /.description-block -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div>
</div>
<!-- /.widget-user -->
</div>
<!-- /.col -->
</div>';
}
?>
You're ending your echo with a ;. You need to concatenate the string with a . instead:
<h5 class="description-header">'.$userRow['userEmail'];'</h5>
<h5 class="description-text">'.$userRow['userSignature'];'</h5>
This should be:
<h5 class="description-header">'.$userRow['userEmail'].'</h5>
<h5 class="description-text">'.$userRow['userSignature'].'</h5>
in
'.$userRow['
quates are conflict with together
change ' and " with together in all lines of your script
and then :
".$userRow['userEmail']."<
be sure will be ok

cycle2 is producing disorderly HTML -- is my data-cycle-slides value correct?

I've used cycle2 a number of times, but am trying to do something a little different with HTML than what I normally would do. Please see my code below. Am I doing the right thing with the "data-cycle-slides" value?
<div class="cycle-slideshow"
data-cycle-fx="scrollHorz"
data-cycle-speed="700"
data-cycle-timeout="3600"
data-cycle-slides="> section > div.is-left">
<section id="is-top">
<?php foreach ($array as $key => $value) { ?>
<div class="is-left ic">
<div class="in">
<!-- more html -->
</div>
</div>
<?php } ?>
<div id="other-stuff">
<p>yo!</p>
</div>
<div id="more-stuff">
<p>hey!</p>
</div>
</section>
</div>
It looks ok to me, and when I view the page source, nothing seems amiss. But when I have a look in Firebug or the Firefox developer tools, things appear to be out of order. If there are two items in the array, I see something like this...
<div class="cycle-slideshow" data-cycle-fx="scrollHorz" <!-- et cetera -- >>
<div class="is-left ic">
<div class="in">
<!-- more html -->
</div>
</div>
<section id="is-top">
<div id="other-stuff">
<p>yo!</p>
</div>
<div id="more-stuff">
<p>hey!</p>
</div>
</section>
<div class="is-left ic">
<div class="in">
<!-- more html -->
</div>
</div>
<div class="is-left ic">
<div class="in">
<!-- more html -->
</div>
</div>
</div>
Note that items that should appear inside of #is-top are appearing outside of that section. Also, there are somehow three .is-left items in firebug, when there should be two.
I don't know if this is a case where firebug is making a mistake and causing me some confusion, or if I'm taking the wrong approach with cycle2.

Where can I find the file PHP is fetching text/table from?

I recently inherited a website with a horrible file structure. I need to update some content (text) but I can’t find where it is being defined. The database table does not have the information, so I'm guessing the text is being defined elsewhere. Is there a tool or "trick" in Chrome Dev Tools to find the content source? Your help is much appreciated!
***Snippet from PHP File:
<div id="product_wrapper" class="add-bottom30">
<div class="columns sixteen">
<div class="columns twelve add-bottom60 catalogue">
<!-- Pager -->
<?php include('sql-' . $_SESSION['lang'] . '/promos.php');?>
</div>
<div class="columns four side">
<h5 style="margin-bottom:25px;">FLYERS</h5>
<ul>
<li style="background-color:#0065a4;">
<?php echo flyer_jet_2016; (where the text I need to change lives) ?>
</li>
</ul>
</div>
<div class="clear"><!-- ClearFix --></div>
</div>
</div>
*** Snippet from source code ("View Source" in Chrome):
<div class="columns four side">
<h5 style="margin-bottom:25px;">FLYERS</h5>
<ul>
<li style="background-color:#0065a4;">
<span class="icon" data-icon="(" style="color:#fff;margin-bottom:15px;"></span><br>Tool Storage<br>Solutions 2016
</li>
</ul>
</div>
<div class="clear"><!-- ClearFix --></div>
</div>

Php syntax for Bootstrap cart slider

I am trying to do the Cart slider which can be seen at http://bootsnipp.com/snippets/Pbnxx
I am struggling with proper PHP syntax. Can anyone help me out?
The way I see it that I need to prepend .item and .row for every 4 columns, but something is glitching and doesn't work as expected
<div class="container">
<div class="row">
<div class="col-md-9">
<h3>TITLE </h3>
</div>
<div class="col-md-3">
<!-- Controls -->
<div class="controls pull-right hidden-xs">
<a class="left fa fa-chevron-left btn btn-success" href="#carousel-example"
data-slide="prev"></a>
<a class="right fa fa-chevron-right btn btn-success" href="#carousel-example"
data-slide="next"></a>
</div>
</div>
</div>
<div id="carousel-example" class="carousel slide hidden-xs" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php
while ( $query->have_posts() ) :
$query->the_post();
// make new slide every 4 columns
if($i % 4 == 0) : ?>
<div class="item <?php if($a++ == 0) echo 'active'; ?>">
<div class="row">
<?php endif; ?>
<div class="col-sm-3">
<div class="col-item">
<?php echo $i; ?>
</div>
</div>
<!-- end slide every 4 columns -->
<?php if($i++ % 4 == 0) : ?>
</div> <!-- row -->
</div> <!-- slide -->
<?php endif; ?>
<?php endwhile; ?>
</div> <!-- end carousel -->
</div> <!-- carousel-example -->
</div> <!-- container -->
I think your .row should be also .item because you want to slide 4 items at time.
Here you have my code using smarty. I used array_chunk($items, 4) and nested loops.
<div class="carousel-inner">
{foreach $recipebox.recipes as $key=>$recipeSet}
{if $key == 0}
<div class="row item active">
{else}
<div class="row item">
{/if}
{foreach $recipeSet as $recipe }
<div class="col-xs-3">
// box content
</div>
{/foreach}
</div>
{/foreach}
</div>

Categories