I have an HTML markup like bellow-
<div class="f_product_slider slick">
<div class="row slider_item">
<div class="col-lg-5 col-sm-6">
<div class="item">
<img src="image/bike/cycle_2.png" alt="">
<div class="content text-right">
<h6>Specialized Sirrus Carbon - 2018</h6>
<p>Slayer Bike Expert</p>
</div>
</div>
</div>
<div class="col-lg-5 col-sm-6">
<div class="item item_two">
<img src="image/bike/cycle_2.png" alt="">
<div class="content text-right">
<h6>Specialized Sirrus Carbon - 2018</h6>
<p>Slayer Bike Expert</p>
</div>
</div>
</div>
</div>
<div class="row slider_item">
<div class="col-lg-5 col-sm-6">
<div class="item">
<img src="image/bike/cycle_2.png" alt="">
<div class="content text-right">
<h6>Specialized Sirrus Carbon - 2018</h6>
<p>Slayer Bike Expert</p>
</div>
</div>
</div>
<div class="col-lg-5 col-sm-6">
<div class="item item_two">
<img src="image/bike/cycle_2.png" alt="">
<div class="content text-right">
<h6>Specialized Sirrus Carbon - 2018</h6>
<p>Slayer Bike Expert</p>
</div>
</div>
</div>
</div>
</div>
Here, every row items containing two items. That's mean, every two loop items rendered in every step of the loop.
I'm giving here a visual example of this loop-
How can I make it possible with PHP while loop?
Please, don't hesitate to ask me for more details if you get confused by the question.
With for:
<div class="f_product_slider slick">
<?php for($slideCounter = 0; $slideCounter < 2; $slideCounter++) { ?>
<div class="row slider_item">
<?php for($colCounter = 0; $colCounter < 2; $colCounter++) { ?>
<div class="col-lg-5 col-sm-6">
<div class="item">
<img src="image/bike/cycle_2.png" alt="">
<div class="content text-right">
<h6>Specialized Sirrus Carbon - 2018</h6>
<p>Slayer Bike Expert</p>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
With while:
<div class="f_product_slider slick">
<?php
$slideCounter = 0;
while($slideCounter < 2) {
$slideCounter++ ?>
<div class="row slider_item">
<?php
$colCounter = 0;
while($colCounter < 2) {
$colCounter++ ?>
<div class="col-lg-5 col-sm-6">
<div class="item">
<img src="image/bike/cycle_2.png" alt="">
<div class="content text-right">
<h6>Specialized Sirrus Carbon - 2018</h6>
<p>Slayer Bike Expert</p>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
Related
I have a little problem that might be syntax (since I'm not that good at php). Basically, I'm de-wrapping a code where there will be records where there will be a date (in this case, a foundation date, for example; 20-08-2027). So I created an "if". If there are records with the date, for example, 2027, the records appear. If there is not, then an error message will be displayed saying that there is still no record made with that date. I've tried a few things, but nothing worked. At this point, an error appears. Below will be the error. Please try to help me. It's no use saying more technical things, because I'm not that good at php. Thank you.
Error: "Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/host/public_html/template/year/2027.php on line 300"
2027.php
<section class="content products">
<div class="container">
<h1 class="hidden">Eventos</h1>
<div class="row">
<div class="col-sm-10">
<div class="row grid" id="products">
<div class="releated-products">
<div class="row grid" id="products">
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0) {
while($regi=mysqli_fetch_array($resu)){
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php
} else{
?>
<p>Nada!</p>
<?php
}
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
The reason you are getting the error because you have while loop in your if block that you are not closing.
Check the code below for this fixed version.
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0):
while($regi=mysqli_fetch_array($resu)):
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php endwhile; else: ?>
<p>Nada!</p>
<?php
endif;
?>
Move the last } bracket above }else{
<section class="content products">
<div class="container">
<h1 class="hidden">Eventos</h1>
<div class="row">
<div class="col-sm-10">
<div class="row grid" id="products">
<div class="releated-products">
<div class="row grid" id="products">
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0) {
while($regi=mysqli_fetch_array($resu)){
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php
} // while()
} else{
?>
<p>Nada!</p>
<?php
}
// } //wrong bracket
?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
For your own sanity it is a good idea leave a comment after closing bracket of a long code, so you know which block it belongs to.
Compiler can't be wrong, if it says there's syntax error then there is. The bracket before the else is closing the while loop - hence else cannot be used there, close the if condition. Here's the corrected code:
<section class="content products">
<div class="container">
<h1 class="hidden">Eventos</h1>
<div class="row">
<div class="col-sm-10">
<div class="row grid" id="products">
<div class="releated-products">
<div class="row grid" id="products">
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0) {
while($regi=mysqli_fetch_array($resu)) {
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
/* 2 brackets { */
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php
} // while loop
} // if condition
else {
?>
<p>Nada!</p>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
hope this helps. 👍
Below is my code the posts are displaying fine with card but I have tried many times changing it to carousel but it didn't worked.
I wanted to use the same carousel from the link below.
Carousel reference: https://gosnippets.com/snippets/bootstrap-carousel-with-cards-in-3-columns
<?php
//var_dump($get_packages_list);
if($get_packages_list){
foreach($get_packages_list as $get_package){?>
<div class="row">
<div class="col-md-12">
<div class="packages_list_body">
<div class="packages_cards_inner_wrap" id="package-<?php echo $get_package->post_name;?>">
<h2 id="bundle_p_title" style="color:#a52a2a; margin-left: 12px;"><?php echo $get_package->post_title.' - <small>'.$default_plan_title.'</small>';?></h2>
<div class="packages_cards row">
<?php
$podcasts = get_field('podcasts', $get_package->ID);
$minimum_price = get_field('minimum_price', $get_package->ID);
$package_title = 'Pay at least $'.$minimum_price.' for these '.$podcast_count.' items';
foreach($podcasts as $podcast){
$podcast_details = get_post($podcast);
$image = get_the_post_thumbnail_url(get_the_ID(), array('250', '250'));
$image = $image?$image:wp_get_attachment_image_src(8059, 'thumbnail');
?>
<div class="col-md-3">
<div class="card <?php echo 'package-'.$get_package->ID.' podcast-'.$podcast_details->ID;?>" data-price="<?php echo $minimum_price;?>" data-packageid="<?php echo $get_package->ID;?>">
<img src="<?php echo $image[0];?>" alt="<?php echo $podcast_details->post_title; ?>" class="card-img-top">
<div class="card-body">
<h3><?php echo substr($podcast_details->post_title, 0, 20) . ' ...';?></h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
</div>
</div>
<?php }?>
</div>
</div>
</div>
</div>
</div>
<?php }
}?>
I have to make it all HTML to see that if it works. I hope you can rewrite it back to PHP later.
<div class="row">
<div class="col-md-12">
<div class="packages_list_body">
<div class="packages_cards_inner_wrap" id="package-xxx">
<h2 id="bundle_p_title" style="color:#a52a2a; margin-left: 12px;">Title here</h2>
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active group-of-cards">
<div class="packages_cards row">
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title1</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title2</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title3</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
</div>
<!--.packages_cards-->
</div>
<!--.group-of-cards-->
<div class="carousel-item group-of-cards">
<div class="packages_cards row">
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title4</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title5</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title6</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
</div>
<!--.packages_cards-->
</div>
<!--.group-of-cards-->
</div>
<!--.carousel-inner-->
</div>
<!--.carousel-->
</div>
<!--.packages_cards_inner_wrap-->
</div>
<!--.packages_list_body-->
</div>
</div>
<!--.row-->
See it in action ( https://jsfiddle.net/qt60whLf/ ).
Bootstrap 4 document ( https://getbootstrap.com/docs/4.0/components/carousel/ ).
I want the information tag to be at the right side of the web page. Rest of the things are in the middle of the page. While I am not able to move the information to the right side. Also, because of it the footer disappeared. While I remove the information code, the footer works. Please help me right-align the information widget and also have the footer too.
<div class="container">
<div class="card border-light mb-3 text-center">
<p class="card-header">Videos</p>
</div>
<div id="userSuccess" class="hide" role="alert">
<div id="successUserContent"></div>
</div>
<div class="row" id="userVid">
<?php
$allVid = Schema::getAll();
for ($i = 0; $i < count($allVid); $i++) {
echo <<<HTML
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<div class="card-body">
<img class="card-img-top" src="http://placehold.it/700x400" alt="">
<h4 class="card-title">{$allVid[$i]->getTitle()} </h4>
</div>
</div>
</div>
HTML;
}
?>
</div>
<div class="row">
<div class="col-md-4 order-md-2 mb-4">
<div class="card my-4">
<h5 class="card-header">Information</h5>
<div class="card-body">
<div class="row">
<ul class="list-unstyled mb-0">
<li>
...
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
require_once './page/footer.php';
?>
For right align, you'll want to add the class of "justify-content-end" after your "row" class.
<div class="row justify-content-end"><!-- ADDED HERE-->
<div class="col-md-4 order-md-2 mb-4">
<div class="card my-4">
<h5 class="card-header">Information</h5>
<!-- REST OF YOUR CODE-->
For your footer, you'll need to wrap your URL in parenthesis.
<?php require_once('/yourdirectory/yourfooter.php'); ?>
I am using simple_html_dome and I want to grab experience, education, and title.
By my code, I am getting (Call to a member function find() on null in ) error message but title is showing error is ($notrmjobs = $item->find('div[class=norm-jobs-wrapper]',0);) here.
What is the core rules to catch HTML tag by find method?
<div class="boxed">
<div class="row">
<div class="col-md-12">
<div class="norm-jobs-wrapper" onclick="DivOpen('id=734675&fcatId=1&ln=1');">
<div class="row">
<div class="col-sm-3 col-sm-push-3">
<!--<div class="row">
<div class="col-sm-12">
<div class="comp_logo"><img src="images/38951.jpg" alt=""></div>
</div>
</div>-->
</div>
<div class="col-sm-9 col-sm-pull-9">
<div class="row">
<div class="col-sm-12">
<div class="comp-name-text">GBA Techno Pvt. Ltd.</div>
</div>
<div class="col-sm-12">
<div class="job-title-text">
<a onclick="clickJObTitle()" target="_blank" href="jobdetails.asp?id=734675&fcatId=1&ln=1">
Sr. Executive, Accounts
</a>
</div>
</div>
<div class="col-sm-12">
<div class="edu-text">
<div class="row">
<div class="col-sm-2">
<div class="edu-text-s">
Education:
</div>
</div>
<div class="col-sm-10">
<div class="edu-text-d">
Masters/ MBA in Accounts or Finance from any reputed university
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="row">
<div class="col-sm-9">
<div class="exp-text">
<div class="row">
<div class="col-sm-2">
<div class="exp-text-s">Experience:</div>
</div>
<div class="col-sm-10">
<div class="exp-text-d">
At least 3 year(s)
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="dead-text">
<div class="dead-text-s">Deadline: </div>
<div class="dead-text-d">
<strong>Dec 13, </strong>2017
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include 'simple_html_dom.php';
$html = file_get_html('http://jobs.bdjobs.com/jobsearch.asp?fcatId=1&icatId=');
$boxed = $html->find('div[class=boxed]',0);
$raw = $boxed->find('div[class=row]');
foreach($raw as $key => $loop){
$item = $loop->find('div[class=col-md-12]',0);
$notrmjobs = $item->find('div[class=norm-jobs-wrapper]',0);
$raw = $notrmjobs->find('div[class=row]',0);
$sdivice = $raw->find('div[class=col-sm-9 col-sm-pull-9]',0);
$sraw = $sdivice->find('div[class=row]',0);
$asraw = $sraw->find('div[class=col-sm-12]',0);
$title = $asraw->find('div[class=comp-name-text]',0)->plaintext;
echo $title;
}
?>
I have an array image: lstImageSlider.
I need a loop to foreach that array and insert it into the HTML page.
The HTML code from a theme has structure that is difficult to insert.
This is because it has slider__item--0 - 1 - 2 - 3. Loop this.
I can set this code to foreach $lstImageSlider as $item.
``````````````````````
` thumbnail `
``````````````````````
` image 1 ` image 2 `
``````````````````````
HTML code:
<div class="property__ribon">transaction-related</div>
<div id="properties-thumbs" class="slider slider--small js-slider-thumbs">
<div class="slider__block js-slick-slider">
<div class="slider__item--0"><span>Awesome Kitchen!!!</span></div>
<div class="slider__item--1"><span>2</span></div>
<div class="slider__item--2"><span>3</span></div>
<div class="slider__item--3"><span>Ok</span></div>
<div class="slider__item--0"><span>5</span></div>
<div class="slider__item--1"><span>6</span></div>
<div class="slider__item--2"><span>7</span></div>
<div class="slider__item--3"><span>8</span></div>
<div class="slider__item--0"><span>The end</span></div>
</div>
</div>
<div class="slider slider--thumbs">
<div class="slider__wrap">
<div class="slider__block js-slick-slider">
<div data-slide-rel='0' class="slider__item--0">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='1' class="slider__item--1">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='2' class="slider__item--2">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='3' class="slider__item--3">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='4' class="slider__item--0">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='5' class="slider__item--1">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='6' class="slider__item--2">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='7' class="slider__item--3">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<div data-slide-rel='8' class="slider__item--0">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
</div>
</div>
</div>
</div>
i am not sure which you want , but hope it will help you, create counter and if counter >= 3 then set 0
<div class="property__ribon">transaction-related</div>
<div id="properties-thumbs" class="slider slider--small js-slider-thumbs">
<div class="slider__block js-slick-slider">
<?php
$first_counter = 0;
foreach ($lstImageSlider as $item) {
?>
<div class="slider__item--<?=$first_counter?>"><a href="src/image.jpg" data-gallery-index='<?=$first_counter?>'><img
src="assets/img/lazy-image.jpg" alt=""><span>Awesome Kitchen!!!</span></a></div>
<?php
$first_counter++;
if ($first_counter >= 3) {
$first_counter = 0;
}
}
?>
</div>
</div>
<div class="slider slider--thumbs">
<div class="slider__wrap">
<div class="slider__block js-slick-slider">
<?php
$counter = 0;
foreach ($lstImageSlider as $item) {
?>
<div data-slide-rel='<?= $counter ?>' class="slider__item--<?= $counter ?>">
<div class="slider__img"><img src="assets/img/lazy-image.jpg" alt=""></div>
</div>
<?php
$counter++;
if ($counter >= 3) {
$counter = 0;
}
}
?>
</div>
</div>
</div>
hope it will help you, any confusion then inform me
It's not clear what you're doing with the items, I assume you're updating the document with js? Or you could output your lines of HTML within this loop. Anyway, this is how you can loop over your items and get the correct classname at the same time:
for($i=0; $i < count($lstImageSlider); $i++){
$j = $i % 3;
$item = $lstImageSlider[$i];
$classname = "slider__item--".$j;
}