First three rows(collapsible) shows in container, after three rows it shows out of container - MaterializeCSS

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



First three rows(collapsible) shows in container, after three rows it shows out of container - MaterializeCSS



im trying to fix this, im using foreach php to get the rows from Mysqli Database and display here as collapsibles within container im using MaterializeCSS.



First 3 rows displays as it should within container, after 3 rows it gets out of container.



Here is the PHP and HTML code:


<div class="container" style="margin-top:25px;">

<div class="postOffer right-align">
<button class="btn waves-effect waves-light addOfferBtn" style="background-image: linear-gradient(90deg,#5c258d 0,#4389a2);">Add Recurring Offer </button>
<div class="Offers center-align">

<?php
$counter = 0;
foreach ($u->fetchOffers($_SESSION['user']) as $row)
echo '<div class="createdOffers">
<ul class="collapsible">';
if($counter == 0)
echo '<li class="active">
<div class="collapsible-header active offerTitleCollapsible" data-id="'.$row['id'].'" style="font-weight: 900;">'.$row['offerTitle'].'<i class="material-icons" style="left: 0;">add</i></div>';
else
echo'<li>
<div class="collapsible-header offerTitleCollapsible" data-id="'.$row['id'].'" style="font-weight: 900;">'.$row['offerTitle'].'<i class="material-icons" style="left: 0;">add</i></div>';

echo '<div class="collapsible-body">
<div class="row">
<div class="col s12">
<input id="offerTitleField" class="offerTitleField" placeholder="Offer Name" data-id="'.$row['id'].'" value="'.$row['offerTitle'].'" maxlength="70" type="text">
<div class="left-align" id="titleCharsLeft" style="font-size: 11px; margin-top: -15px; font-weight: 900;">
Characters Left: 70
</div>
</div>
</div>
<div class="row">
<div class="col s12">
<select class="browser-default offerPeriod" data-id="'.$row['id'].'">';

if ($row['offerPeriod'] == "week")
echo '<option active selected value="week">Weekly</option>';
echo '<option value="month">Monthly</option>';
echo '<option value="3months">3 Month</option>';
echo '<option value="6months">6 Month</option>';
echo '<option value="year">1 Year</option>';
elseif ($row['offerPeriod'] == "month")
echo '<option value="week">Weekly</option>';
echo '<option active selected value="month">Monthly</option>';
echo '<option value="3months">3 Month</option>';
echo '<option value="6months">6 Month</option>';
echo '<option value="year">1 Year</option>';
elseif ($row['offerPeriod'] == "3months")
echo '<option value="week">Weekly</option>';
echo '<option value="month">Monthly</option>';
echo '<option active selected value="3months">3 Month</option>';
echo '<option value="6months">6 Month</option>';
echo '<option value="year">1 Year</option>';
elseif ($row['offerPeriod'] == "6months")
echo '<option value="week">Weekly</option>';
echo '<option value="month">Monthly</option>';
echo '<option value="3months">3 Month</option>';
echo '<option active selected value="6months">6 Month</option>';
echo '<option value="year">1 Year</option>';
elseif ($row['offerPeriod'] == "year")
echo '<option value="week">Weekly</option>';
echo '<option value="month">Monthly</option>';
echo '<option value="3months">3 Month</option>';
echo '<option value="6months">6 Month</option>';
echo '<option active selected value="year">1 Year</option>';
else
echo'<option value="" disabled selected>Subscription Period</option>';
echo '<option value="week">Weekly</option>';
echo '<option value="month">Monthly</option>';
echo '<option value="3months">3 Month</option>';
echo '<option value="6months">6 Month</option>';
echo '<option value="year">1 Year</option>';


echo '</select>
</div>
</div>
<div class="row">
<div class="col s6">
<input type="number" id="subscriptionPriceField" class="subscriptionPriceField" data-id="'.$row['id'].'" pattern="[0-9.]*" value="'.$row['offerPrice'].'" placeholder="29.99">
<br>
<div class="left-align" id="priceLimit" style="font-size: 11px; margin-top: -15px; font-weight: 900;">
</div>
</div>
<div class="col s6">
<select class="browser-default" disabled>
<option value="" disabled selected>USD</option>
</select>
</div>
<div class="col s12">
<textarea type="text" id="offerDescription" class="offerDescription" data-id="'.$row['id'].'" name="offerDescription" placeholder="Describe your offer here." maxlength="110">'.$row['offerDescription'].'</textarea>
<div class="left-align" id="charsLeft" style="font-size: 11px; font-weight: 900;">
Characters Left: 110
</div>
</div>
</div>
<hr color="#ddd">
<div class="OfferEditButtons right-align">';
if($u->offerExist($row['id']) != true)
echo '<button class="btn waves-effect waves-light" value="'.$row['id'].'" id="SaveBtn" style="background-color: #98DA86;">Save</button>';
else
echo '<button class="btn waves-effect waves-light" value="'.$row['id'].'" id="SaveBtn" style="background-color: #98DA86;">Update</button>';

echo '</div>
</div>
</div>
</li>
</ul>
</div>';
$counter++;

?>
</div>
</div>





it displays like this(SCREENSHOT):



enter image description here




1 Answer
1



This might certainly be a markup issue. The foreach should run on the <li> and not the <ul>. Bring out initial <li> out of the if condition so that you are sure the <div> tags have their closing tags at the end of the for loop rather than ending the for loop with no closing <li> tag. I also added some <div> tags in the markup.


foreach


<li>


<ul>


<li>


<div>


<li>


<div>


<div class="container" style="margin-top:25px;">
<div class="postOffer right-align">
<button class="btn waves-effect waves-light addOfferBtn" style="background-image: linear-gradient(90deg,#5c258d 0,#4389a2);">Add Recurring Offer </button>
<div class="Offers center-align">

<?php $counter = 0; ?>
<div class="createdOffers">
<ul class="collapsible">
<?php foreach ($u->fetchOffers($_SESSION['user']) as $row) ?>
<li class="<?= $counter == 0 ? 'active' : ''; ?>">
<?php if($counter == 0) ?>
<div class="collapsible-header active offerTitleCollapsible" data-id="<?= $row['id']; ?>" style="font-weight: 900;"><?= $row['offerTitle']; ?><i class="material-icons" style="left: 0;">add</i></div>
<?php else ?>
<div class="collapsible-header offerTitleCollapsible" data-id="<?= $row['id']; ?>" style="font-weight: 900;"><?= $row['offerTitle'] ?><i class="material-icons left" style="left: 0;">add</i></div>
<?php ?>
<div class="collapsible-body">
<div class="row">
<div class="col s12">
<input id="offerTitleField" class="offerTitleField" placeholder="Offer Name" data-id="<?= $row['id']; ?>" value="<?= $row['offerTitle']; ?>" maxlength="70" type="text">
<div class="left-align" id="titleCharsLeft" style="font-size: 11px; margin-top: -15px; font-weight: 900;">Characters Left: 70</div>
</div>
</div>
<div class="row">
<div class="col s12">
<select class="browser-default offerPeriod" data-id="<?= $row['id']; ?>">
<?php if ($row['offerPeriod'] == "week") ?>
<option active selected value="week">Weekly</option>
<option value="month">Monthly</option>
<option value="3months">3 Month</option>
<option value="6months">6 Month</option>
<option value="year">1 Year</option>
<?php elseif ($row['offerPeriod'] == "month") ?>
<option value="week">Weekly</option>
<option active selected value="month">Monthly</option>
<option value="3months">3 Month</option>
<option value="6months">6 Month</option>
<option value="year">1 Year</option>
<?php elseif ($row['offerPeriod'] == "3months") ?>
<option value="week">Weekly</option>
<option value="month">Monthly</option>
<option active selected value="3months">3 Month</option>
<option value="6months">6 Month</option>
<option value="year">1 Year</option>
<?php elseif ($row['offerPeriod'] == "6months") ?>
<option value="week">Weekly</option>
<option value="month">Monthly</option>
<option value="3months">3 Month</option>
<option active selected value="6months">6 Month</option>
<option value="year">1 Year</option>
<?php elseif ($row['offerPeriod'] == "year") ?>
<option value="week">Weekly</option>
<option value="month">Monthly</option>
<option value="3months">3 Month</option>
<option value="6months">6 Month</option>
<option active selected value="year">1 Year</option>
<?php else ?>
<option value="" disabled selected>Subscription Period</option>
<option value="week">Weekly</option>
<option value="month">Monthly</option>
<option value="3months">3 Month</option>
<option value="6months">6 Month</option>
<option value="year">1 Year</option>
<?php ?>
</select>
</div>
</div>

<div class="row">
<div class="col s6">
<input type="number" id="subscriptionPriceField" class="subscriptionPriceField" data-id="<?= $row['id'];?>" pattern="[0-9.]*" value="<?=$row['offerPrice'];?>"
placeholder="29.99"><br>
<div class="left-align" id="priceLimit" style="font-size: 11px; margin-top: -15px; font-weight: 900;"></div>
</div>
<div class="col s6">
<select class="browser-default" disabled>
<option value="" disabled selected>USD</option>
</select>
</div>
<div class="col s12">
<textarea type="text" id="offerDescription" class="offerDescription" data-id="<?=$row['id'];?>" name="offerDescription" placeholder="Describe your offer here."
maxlength="110"><?=$row['offerDescription'];?></textarea>
<div class="left-align" id="charsLeft" style="font-size: 11px; font-weight: 900;">Characters Left: 110</div>
</div>
</div>

<hr color="#ddd">
<div class="OfferEditButtons right-align">
<?php if($u->offerExist($row['id']) != true) ?>
<button class="btn waves-effect waves-light" value="<?=$row['id'];?>" id="SaveBtn" style="background-color: #98DA86;">Save</button>
<?php else ?>
<button class="btn waves-effect waves-light" value="<?=$row['id'];?>" id="SaveBtn" style="background-color: #98DA86;">Update</button>
<?php ?>
</div>
</div>
</li>
<?php $counter++; ?>
</ul>
</div>
</div></div></div>



`





Thank you, it worked.
– smokzz
Aug 13 at 13:13






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard