I am trying to get data from a database and in the frontend I am showing data in cards in 1 row and 2 columns using bootstrap and PHP. But, I am getting the data for the first row but the remaining are cards coming one below one
<?php
$con = mysqli_connect('localhost', 'root', '', 'applicants');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$qry = "select * from feedback";
$result = mysqli_query($con, $qry);
?>
<div class="main-content">
<div class="main-content-inner">
<div class="row">
<div class="col-6 mt-5">
<?php $i=0;
while ($row = $result->fetch_assoc()) {
$i++;?>
<?php if ($i %2 == 0){?>
<!-- <div class="row"> -->
</div>
<div class="col-6 mt-5"><?php } ?>
<div class="card">
<div class="card-body">
<h5 class="card-title"> <?php echo $row['username']?></h5>
<h6 class="card-subtitle mb-2 text-muted"><?php echo $row['email'] ?></h6>
<ul>
<li>
<div class="left alert alert-success" role="alert">
<h6><?php echo $row['subject'] ?></h6>
<p class="card-text"><?php echo $row['message'] ?></p>
</div>
</li>
</ul>
</div>
</div>
<?php if ($i %2 == 0){?>
</div>
<!-- </div> --><?php } ?>
<!-- </div> -->
</div>
<?php } ?>
</div>
</div>
Your tags for the row and cols seem to be off. Please compare them against this code that generates two rows:
<div class="main-content-inner">
<div class="row">
<div class="col-6 mt-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">Name</h5>
<h6 class="card-subtitle mb-2 text-muted">Email</h6>
<ul>
<li>
<div class="left alert alert-success" role="alert">
<h6>Subject</h6>
<p class="card-text">Message</p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="col-6 mt-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">Name</h5>
<h6 class="card-subtitle mb-2 text-muted">Email</h6>
<ul>
<li>
<div class="left alert alert-success" role="alert">
<h6>Subject</h6>
<p class="card-text">Message</p>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-6 mt-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">Name</h5>
<h6 class="card-subtitle mb-2 text-muted">Email</h6>
<ul>
<li>
<div class="left alert alert-success" role="alert">
<h6>Subject</h6>
<p class="card-text">Message</p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="col-6 mt-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">Name</h5>
<h6 class="card-subtitle mb-2 text-muted">Email</h6>
<ul>
<li>
<div class="left alert alert-success" role="alert">
<h6>Subject</h6>
<p class="card-text">Message</p>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Related
I am annoyed because i'm trying to make a forum and I can not select the right categories in my SQL query.
My database is articulate like that :
CATEGORIES (id, category_name, category_description) TOPICS (id, titre, contenu, id_auteur, pseudo_auteur, image_auteur, date_publication, categorie)
I managed to display the categories in my index.php but when I try to display the topics that match the right category, I can not select them.
For example, if I have three topics in 3 different categories, I can not display the "category" that comes from topics, in a category that comes from categories, like "category.php?id=1".
Thanks for your help!
edit: my code :
<?php
session_start();
require('actions/topics/showAllTopicsAction.php');
?>
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="assets/style.css">
<?php include 'includes/head.php'; ?>
<body>
<?php include 'includes/navbar.php'; ?>
<br><br>
<div class="container">
<div class="d-flex flex-wrap justify-content-between">
<div> <button type="button" class="btn btn-shadow btn-wide btn-primary"> <span class="btn-icon-wrapper pr-2 opacity-7"> <i class="fa fa-plus fa-w-20"></i> </span> New thread </button> </div>
<div class="col-10 col-md-3 p-0 mb-3"> <input type="text" class="form-control" placeholder="Search..."> </div>
</div>
<div class="card mb-3">
<div class="card-header bg-dark text-white pl-0 pr-0">
<div class="col ml-3">Sujets</div>
<div class="col-4 text-muted">
<div class="row no-gutters align-items-center">
<div class="col-4">Réponses</div>
<div class="col-8">Dernier post</div>
</div>
</div>
</div>
<?php while ($topic = $getAllTopics->fetch()) { ?>
<div class="card-body py-3">
<div class="row no-gutters align-items-center">
<div class="col"> <a href="#" class="text-big" data-abc="true">
<?= $topic['titre']; ?>
<div class="text-muted small mt-1">Publié par <?= $topic['pseudo_auteur']; ?> le <?= $topic['date_publication']; ?></div>
</div>
<div class="d-none d-md-block col-4">
<div class="row no-gutters align-items-center">
<div class="col-4">12</div>
<div class="media col-8 align-items-center"> <img src="assets/img/anonymous.png" alt="" class="d-block ui-w-30 rounded-circle">
<div class="media-body flex-truncate ml-2">
<div class="line-height-1 text-truncate">?Titre du sujet?</div> ?Auteur?
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<nav>
<ul class="pagination mb-5">
<li class="page-item disabled"><a class="page-link" href="javascript:void(0)" data-abc="true">«</a></li>
<li class="page-item active"><a class="page-link" href="javascript:void(0)" data-abc="true">1</a></li>
<li class="page-item"><a class="page-link" href="javascript:void(0)" data-abc="true">2</a></li>
<li class="page-item"><a class="page-link" href="javascript:void(0)" data-abc="true">3</a></li>
<li class="page-item"><a class="page-link" href="javascript:void(0)" data-abc="true">»</a></li>
</ul>
</nav>
</div>
</body>
</html>
<?php
require('actions/database.php');
//Récupérer les topics par défaut sans recherche
$getAllTopics = $bdd->query('SELECT * FROM topics WHERE categorie ORDER BY id DESC LIMIT 0,5');
You need to substitute the id parameter into the query.
if (!isset($_GET['id'])) {
$id = intval($_GET['id']);
$statement = $bdd->query("SELECT * FROM topics WHERE categorie = ? ORDER BY id DESC limit 5");
$statement->execute([$id]);
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
// display the results from $rows
}
I wanna show the projects in an horizontal alignment, but as you can see in the image below they are vertically.
This my code:
<section class="bg-light" id="portfolio">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase">Projects</h2>
<h3 class="section-subheading text-muted">Projects elaborated throughout the years</h3>
</div>
</div>
#foreach (\App\Project::all()->take(6) as $project)
<div class="row">
<div class="col-md-4 col-sm-6 portfolio-item">
<a class="portfolio-link" data-toggle="modal" href="#portfolioModal1">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fas fa-plus fa-3x"></i>
</div>
</div>
<img class="img-fluid" src="img/portfolio/project.jpg" alt="">
</a>
<div class="portfolio-caption">
<h5>Project ID: {{ $project->id }}</h5>
<p class="text-muted">{{ $project->title }}</p>
</div>
</div>
#endforeach
</div>
</div>
What am i missing here?
You start row in loop after every col- item.
Try this
<section class="bg-light" id="portfolio">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase">Projects</h2>
<h3 class="section-subheading text-muted">Projects elaborated throughout the years</h3>
</div>
</div>
<div class="row">
#foreach (\App\Project::all()->take(6) as $project)
<div class="col-md-4 col-sm-6 portfolio-item">
<a class="portfolio-link" data-toggle="modal" href="#portfolioModal1">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fas fa-plus fa-3x"></i>
</div>
</div>
<img class="img-fluid" src="img/portfolio/project.jpg" alt="">
</a>
<div class="portfolio-caption">
<h5>Project ID: {{ $project->id }}</h5>
<p class="text-muted">{{ $project->title }}</p>
</div>
</div>
#endforeach
</div>
</div>
</section>
I am getting mad
I had those variables
$wwa_section_title = get_field('wwa_section_title');
$wwa_section_description = get_field('wwa_section_description');
$wwa_section_body = get_field('wwa_section_body');
$wwa_section_image_1 = get_field('wwa_section_image_1');
$wwa_section_image_2 = get_field('wwa_section_image_2')
And this is the HTML section
<div class="container-fluid about-company">
<div class="container">
<div class="row">
<div class="col-xs-12 hero-title text-center">
<h2 class="text-capitalize">
<?php
echo $wwa_section_title;
?>
</h2>
<p class="hero-paragraph">
<?php
echo $wwa_section_body;
?>
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="row">
<div class="col-xs-4 col-xs-offset-4">
<img src="<?php echo $wwa_section_image_2['url'];?>" alt="" class="img-responsive">
</div>
<div class="col-xs-4">
<img src="<?php echo $wwa_section_image_1['url'];?>" alt="" class="img-responsive">
</div>
</div>
<div class="row">
<div class="col-xs-8 col-xs-offset-4">
<p class="about-paragraph small">
<?php
echo $wwa_section_description;
?>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-4 col-xs-offset-4">
<ul class="about-us-list">
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Ipsum is simply text of the stry simply</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Dummy text of the print</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Ipsum is simply text of the stry simply</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Dummy text of the print</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Ipsum is simply text of the stry simply</div>
</li>
</ul>
</div>
<div class="col-xs-4">
<ul class="about-us-list">
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Ipsum is simply text of the stry simply</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Dummy text of the print</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Ipsum is simply text of the stry simply</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Dummy text of the print</div>
</li>
<li class="about-us-list-item">
<div class="about-list-item-check">
<i class="icofont icofont-checked"></i>
</div>
<div class="about-list-item-text">Ipsum is simply text of the stry simply</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
When I transfer this code into a template part and try to render it, the variables become empty.
Once I role back and return the whole code into the page template it wotks fine
I tried to use $post->ID and did not work
I tried to use the_field() instead and did not work
You don't explain at which place in your code you initialize your variables, so I can just guess what might be the problem.
The get_field function of ACF can be called with $post_id as second parameter. If you don't add that one, the get_field call should be inside The Loop.
Finally, I found the solution!!!
I did not use wp_reset_query() after the last while of the section that is before this section (about section which code in the question)
when I added
<? endwhile; wp_reset_query(); ?>
the problem resolved
Hello guys I'm working on a wordpress theme/template and I'm having problems when clicking on blog post title in index.html. It will redirect me to correct link on address bar however, single.php is not displaying anything. I'm not sure if the page is getting called or what's actually going on. If you can weight your 2cents thanks here's the link to wordpress blog: http://pctechtips.org/testblog
index.php
<?php get_header(); ?>
<!-- jumbotron -->
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4"><?php bloginfo('name'); ?></h1>
<p class="lead"><?php bloginfo('description'); ?></p>
</div>
</div>
<!-- /jumbotron -->
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Entries Column -->
<div class="col-md-8">
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<!-- Blog Post -->
<div class="mb-4">
<div class="card-body">
<a href="<?php the_permalink(); ?>">
<h2 class="card-title"><?php the_title(); ?></h2>
</a>
<p class="blog-post-meta">
<?php echo Date('M d, Y'); ?> by <?php the_author(); ?>
</p>
<!-- feature image -->
<?php if(has_post_thumbnail()) : ?>
<div class="post-thumb">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<p><?php __('No Post Found!'); ?></p>
<?php endif; ?>
<!-- Pagination -->
<ul class="pagination justify-content-center mb-4">
<li class="page-item">
<a class="page-link" href="#">← Older</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="#">Newer →</a>
</li>
</ul>
</div>
<!-- Sidebar Widgets Column -->
<div class="col-md-4">
<!-- Search Widget -->
<div class="card my-4">
<h5 class="card-header">Search</h5>
<div class="card-body">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-secondary" type="button">Go!</button>
</span>
</div>
</div>
</div>
<!-- Categories Widget -->
<div class="card my-4">
<h5 class="card-header">Categories</h5>
<div class="card-body">
<div class="row">
<div class="col-lg-6">
<ul class="list-unstyled mb-0">
<li>
Web Design
</li>
<li>
HTML
</li>
<li>
Freebies
</li>
</ul>
</div>
<div class="col-lg-6">
<ul class="list-unstyled mb-0">
<li>
JavaScript
</li>
<li>
CSS
</li>
<li>
Tutorials
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Side Widget -->
<div class="card my-4">
<h5 class="card-header">Side Widget</h5>
<div class="card-body">
You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!
</div>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
<?php get_footer(); ?>
single.php
<?php get_header(); ?>
<!-- jumbotron -->
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4"><?php bloginfo('name'); ?></h1>
<p class="lead"><?php bloginfo('description'); ?></p>
</div>
</div>
<!-- /jumbotron -->
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Entries Column -->
<div class="blog-post col-md-8">
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<!-- Blog Post -->
<div class="blog-post-title mb-4">
<h2 class="card-title"><?php the_title(); ?></h2>
<p class="blog-post-meta">
<?php echo Date('M d, Y'); ?> by <?php the_author(); ?>
</p>
<!-- feature image -->
<?php if(has_post_thumbnail()) : ?>
<div class="post-thumb">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<p class="card-text"><?php the_content(); ?></p>
<hr>
<!-- comments -->
<?php comments_templates(); ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<p><?php __('No Post Found!'); ?></p>
<?php endif; ?>
<!-- Pagination -->
<ul class="pagination justify-content-center mb-4">
<li class="page-item">
<a class="page-link" href="#">← Older</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="#">Newer →</a>
</li>
</ul>
</div>
<!-- Sidebar Widgets Column -->
<div class="col-md-4">
<!-- Search Widget -->
<div class="card my-4">
<h5 class="card-header">Search</h5>
<div class="card-body">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-secondary" type="button">Go!</button>
</span>
</div>
</div>
</div>
<!-- Categories Widget -->
<div class="card my-4">
<h5 class="card-header">Categories</h5>
<div class="card-body">
<div class="row">
<div class="col-lg-6">
<ul class="list-unstyled mb-0">
<li>
Web Design
</li>
<li>
HTML
</li>
<li>
Freebies
</li>
</ul>
</div>
<div class="col-lg-6">
<ul class="list-unstyled mb-0">
<li>
JavaScript
</li>
<li>
CSS
</li>
<li>
Tutorials
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Side Widget -->
<div class="card my-4">
<h5 class="card-header">Side Widget</h5>
<div class="card-body">
You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!
</div>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
<?php get_footer(); ?>
I have written a php script which uses Bootstrap Accordion.
My Problem is as follows:-
Data is displayed correctly in the accordion for all records but when i click on respective accordion..none of them pop-open n close except the accordion of the very first record displayed i.e only the first accordion is working perfectly fine but for rest of the records, accordion displays correct data but does not pop-open n close at all.
Please help if anyone can
Here is the code which i have written
<div class="row">
<?php while ($row = mysql_fetch_assoc($sql_result)) { ?>
<div class="col-sm-6">
<div class="card" style="width: 25rem;">
<h3 class="card-header card-warning text-center"><?php echo $row['dlocation'] ?></h3>
<img class="card-img-top img-fluid" src="<?php echo $row['dimage'] ?>" alt="Card image cap">
<!--ACCORDION START-->
<div id="accordion" role="tablist" aria-multiselectable="true">
<div class="card">
<div class="card-header" role="tab" id="headingOne">
<h5 class="mb-0">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Image Description
</a>
</h5>
</div>
<div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne">
<div class="card-block">
<?php echo $row['dimagedescription'] ?>
</div>
</div>
</div>
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<h5 class="mb-0">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Software Used
</a>
</h5>
</div>
<div id="collapseTwo" class="collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="card-block">
<p class="card-text"><?php echo $row['dsoftwareused'] ?></p>
</div>
</div>
</div>
</div>
<!--ACCORDION END-->
<div class="card-block ">
<div class="alert alert-danger" role="alert">
<p class="card-text"><?php echo $row['dimagedescription'] ?></p>
<p class="card-text"><?php echo $row['dsoftwareused'] ?></p>
</div>
<h4><span class="badge badge-default">Designer Information</span></h4>
<h5 class="card-title"><?php echo $row['dname'] ?></h5>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['dcity'])?></h6>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['dmobile'])?></h6>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['dwebsite'])?></h6>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['demail'])?></h6>
</div>
<div class="card-footer">
<small class="text-muted">Design ID:- <?php echo stripcslashes($row['did']) ?> Submitted on :-<?php echo stripcslashes($row['dsubmissiondate']) ?></small>
<br>
</div>
</div>
</div>
<?php } ?>
</div>
My Problem has been solved by assigning unique Accordion ID for each record in the PHP array generated . Thank You.