I'm trying to create a PHP page that displays 6 data from a table at a time however there is a problem with the layout of how these data are displayed, I believe this problem comes from the styling
The layout is supposed to look something like this:
Screen shot 01
Screen shot 02
I have tried playing around with every single div element on the code below, however, I am unable to find the right width that the data is displayed like the image, right now I'm not sure anymore where the problem with the layout comes from.
This is how it looks like:
Screen shot
PHP:
<div id="greenLine"></div>
<div id="content">
<div class="container">
<form action="search_product.php" method="post"> <!--Action: Sent to "search_product.php" Method: The data will be displayed by "post"-->
<label>Search Product:<br></label>
<input type="text" name="search" placeholder="Enter Product Name"> <!--The name of the numbers inputted are "nilai"-->
<input type="submit" id="submit" name="submit" value="Submit">
</form>
<?php
$koneksi = new mysqli ("localhost","REDACTED","REDACTED","cm0491_progress_business_db_2");
$sql = "SELECT * FROM `product_tbl` LIMIT 6";
$querynews = $koneksi->query($sql);
$rownews = $querynews->fetch_assoc();
// var_dump($rownews); exit;
do {
?>
<div class="product_item">
<div class="number_icon"><?php echo $rownews['id_product']; ?></div>
<h2 class="product_title"><?php echo $rownews['name_product']; ?></h2>
<img src="images/<?php echo $rownews['gambar_product']; ?>"width="200"><br>
<p class="product_desc"><?php echo $rownews['description_product']; ?>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.
</p>
Read More<br><br><br>
</div>
<?php }while($rownews = $querynews->fetch_assoc()); ?>
</div>
<!--- END CONTENT WRAPPER -->
</div>
CSS:
#greenLine { background:url(../images/bg_top_img.jpg) center no-repeat #305D00; height:20px;}
#content { background:#fff; min-height:500px; margin-left:0%;}
.container {width:1200px; height:100%;margin:auto; overflow:auto; overflow-y:hidden; overflow-x:hidden; margin-left:20%;}
.product_item { min-height:280px; width:270px; margin:20px; float:left;}
.number_icon { height:56px; width:56px; background:url(../images/dropcap1.gif); text-align:center; font-size:43px; float:left; margin-bottom:10px; color:#FFF; }
.product_desc { line-height:20px; min-height:60px; color:#696969; margin-top:10px; font-size:14px; font-style:italic; auto;}
I'm genuinely confused with what's happening to the layout and would greatly appreciate anyone willing to help, thank you.
P.S Avoid posting database variables or passwords
Use flex to achieve consistent results, I have your removed php codes for simplicity, just echo where necessary
.product_item{
display:flex;
flex-direction:column;
}
.product_item .title_area{
display:flex;
flex:1;
align-items: center;
}
.product_item .number_icon{
background:green;
width:20px;
height:20px;
border-radius:50%;
color:white;
text-align:center;
line-height:20px;
margin-right:5px;
}
.product_item img{
width:100%;
max-height:200px;
object-fit:cover;
}
<div class="container">
<div class="product_item">
<div class="title_area">
<div class="number_icon">1</div>
<h2 class="product_title">Furniture</h2>
</div>
<img src="http://placehold.it/200x150">
<p class="product_desc">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.
</p>
Read More<br><br><br>
</div>
</div>
<!--- END CONTENT WRAPPER -->
</div>
Related
I have a controller for homepage which gives $posts var which includes that post title and body and sometimes there may be a large amount of text in the body
return view('posts.index',compact('posts'));
and I want to hide all paragraph text and add a button called ReadMore which shows full paragraph
I saw the following bootstrap examples
function myFunction() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
<h2>Read More Read Less Button</h2>
<p>Lorem ipsum imperdiet, nulla et dictum interdum, nisi lorem egestas vitae scel<span id="dots">...</span><span id="more">erisque enim nibh tempor porta.</span></p>
<button onclick="myFunction()" id="myBtn">Read more</button>
in the above example text there is span id in middle and here I don't know how do I add that span between $post->body data. is there any way to make a ReadMore and ShowLess feature?
I am currently showing data as
<p>{!!$post->body!!} </p>
Try something like given below code:
{{ substr( $post->body, 0, random_int(60, 150)) }}
And for read more you can link the single article in anchor tag:
Read more
I have a CSS approach. You can set a CSS class to style it as an truncated text (when the max height exceeded with long text):
.post .post-short-description {
height: 36px;
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 2; /* How many lines before truncated */
-webkit-box-orient: vertical;
}
In your view.blade.php:
#php
$hasLongBody = strlen($p->body) >= 150;
#endPhp
<div class="post">
<h3> {{ $p->title }} </h3>
<p class="post-short-description"> {{ $p->body }} </p>
<a href="{{ route('postDetail', $p->id) }}" #class([
'd-none' => !$hasLongBody
])> Readmore </a>
</div>
I have a created a custom post type with team members and I want to hover on one member and show the overlay-text for that member, then over on the next member show the overlay text for the next member and so on.
Right now when I hover over a random team member it shows all the "overlay-text" divs :
Here is my code:
<?php
$loop = new WP_Query( array( 'post_type' => 'team', 'orderby'=>'post_id', 'order'=>'ASC' ) );
if($loop->have_posts() ) :
while($loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-sm-4">
<div class="team-member">
<div class="member-img">
<?php the_post_thumbnail(); ?>
</div>
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<div class="overlay-text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem maxime id accusantium voluptates. Assumenda, maiores illum nemo aspernatur pariatur. Magnam nihil, enim rerum cupiditate reprehenderit animi dolorum eveniet, voluptas explicabo.</p>
</div>
</div>
</div>
<?php endwhile;
endif;
?>
I know the overlay-text paragraph is hard coded I am trying to find a solution to this also.
CSS for overlay-text:
.team-member .overlay-text {
opacity: 0;
visibility: hidden;
background: rgba(15, 175, 151, 0.95) none repeat scroll 0 0;
color: #fff;
bottom: 0;
left: 15px;
padding: 15px;
position: absolute;
right: 15px;
top: 0;
transition: all 0.5s ease-in-out 0s;
}
.team-member .overlay-text.active {
opacity: 1;
visibility: visible;
}
Javascript for overlay text:
function showOverlay() {
jQuery('.team-member').hover(function(){
jQuery('.overlay-text').addClass('active');
},
function(){
jQuery('.overlay-text').removeClass('active');
});
}
you need this so it only adds the class to that specific one
JS:
function showOverlay() {
$('.team-member').on('mouseenter',function(){
$(this).find('.overlay-text').addClass('active');
}).on('mouseleave',function(){
$(this).find('.overlay-text').removeClass('active');
});
}
I am using the code snippet available here
My PHP code is :
<?PHP
/*** This is for bottomless listing of record from a table ****/
$sql = 'SELECT * FROM agency_list ORDER BY id DESC LIMIT 0, 5';
$query = $dbo4->prepare($sql); // dbo4 coming from config.php
$query->execute();
$list = $query->fetchAll();
?>
The relevant css code is:
.content {
padding: 10px;
min-height: 100px;
text-align: center;
}
#loader {
text-align: center;
display: none;
}
#items {
list-style: none;
text-align: left;
}
#items li {
margin: 0 0 10px 0;
background: #FFFFFF; /* original -- f1f0f0*/
border: 1px solid #999999;
border-radius: 5px;
color: #333333;
}
#items li h2 {
font-size: 18px;
padding: 5px;
}
#items li p {
padding: 5px;
}
The java script code (end-less-scroll.js) is as following:
var is_loading = false; // initialize is_loading by false to accept new loading
var limit = 5; // limit items per page
$(function() {
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
if (is_loading == false) { // stop loading many times for the same page
// set is_loading to true to refuse new loading
is_loading = true;
// display the waiting loader
$('#loader').show();
// execute an ajax query to load more statments
$.ajax({
url: 'load_more.php',
type: 'POST',
data: {last_id:last_id, limit:limit},
success:function(data){
// now we have the response, so hide the loader
$('#loader').hide();
// append: add the new statments to the existing data
$('#items').append(data);
// set is_loading to false to accept new loading
is_loading = false;
}
});
}
}
});
});
Above code is invoking load_more.php which has following code:
<?PHP
include 'config.php';
$last_id = $_POST['last_id'];
$limit = 5;
if (isset($_POST['limit']))
{
$limit = intval($_POST['limit']);
}
// selecting the items for page params
try
{
$sql = 'SELECT * FROM agency_list WHERE id > :last_id ORDER BY id DESC LIMIT 0, :limit';
$query = $dbo4->prepare($sql);
$query->bindParam(':last_id', $last_id, PDO::PARAM_INT);
$query->bindParam(':limit', $limit, PDO::PARAM_INT);
$query->execute();
$list = $query->fetchAll();
}
catch (PDOException $e)
{
echo 'PDOException : '. $e->getMessage();
}
$last_id = 0;
foreach ($list as $rs)
{
$last_id = $rs['id'];
?>
<li>
<h2> <a href='#'><?PHP echo '[' .$rs['id'] .'] ' . $rs['agency_nm']; ?></a>
<img height = "32px" width = "32px" src="images/face_smile_1.png"></h2>
<blockquote>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis?
Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis.
Duo Reges: constructio interrete.
<BR>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis?
Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis.
Duo Reges: constructio interrete.
</p>
</blockquote>
<h5> <?PHP echo $rs['agency_addr_landmark']; ?></h5>
<h5> <?PHP echo $rs['agency_city']. ' - ' . $rs['agency_pin'] . ' [' . $rs['agency_state'] . '] ' ; ?></h5>
<h5> <?PHP echo $rs['agency_contact_per_1']; ?></h5>
<h5> <font color = "maroon"><?PHP echo $rs['agency_contact_addr1'];?></font></h5>
<p style="align:right;">
Details
Update
More
</p>
<BR>
</li>
<BR>
<?PHP
}
if ($last_id != 0)
{
echo '<script type="text/javascript">var last_id = '.$last_id.';</script>';
}
// sleep for 1 second to see loader, it must be deleted in prodection
sleep(1);
?>
And finally the fetched records are being listed in this div (in HTML file)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="js/end-less-scroll.js"></script>
<div class="row">
<div class="twelve columns">
<div class="content">
<ul id="items">
<?PHP
$last_id = 0;
foreach ($list as $rs)
{
$last_id = $rs['id']; // keep the last id for the paging
?>
<li>
<h2> <a href='#'><?PHP echo '[' .$rs['id'] .'] ' . $rs['agency_nm']; ?></a><img height = "32px" width = "32px" src="images/face_smile_1.png"></h2>
<blockquote>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis? Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis. Duo Reges: constructio interrete.
<BR>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis? Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis. Duo Reges: constructio interrete.
</p>
</blockquote>
<h5> <?PHP echo $rs['agency_addr_landmark']; ?></h5>
<h5> <?PHP echo $rs['agency_city']. ' - ' . $rs['agency_pin'] . ' [' . $rs['agency_state'] . '] ' ; ?></h5>
<h5> <?PHP echo $rs['agency_contact_per_1']; ?></h5>
<h5> <font color = "maroon"><?PHP echo $rs['agency_contact_addr1'];?></font></h5>
<p style="align:right;">
Details
Update
More
</p>
<BR>
</li>
<BR>
<?PHP
}
?>
<script type="text/javascript">var last_id = <?PHP echo $last_id; ?>;</script>
</ul>
<!-- this is the paging loader, now is hidden, it wiil be shown when we scroll to bottom -->
<p id="loader"><img src="images/ajax-loader.gif"></p>
</div><!-- content -->
<hr>
</div>
</div>
My problem is that
(1) The code is working perfectly fine if I sort the records by ASC order in both the MySQL queries given. However, if I change the sorting order from ASC (as given in the linked tutorial) to DESC, the logic only lists for 5 records, then first 4, 3, 2, 1 records again and stops work. I know I am doing something very silly in the logic, but unable to find my mistake. Please help me.
(2) Assume that I need to sort by some other column (which is not the PRIMARY key - id being PRIMARY KEY here) e.g. suppose I want to sort the records by agency_nm and the list them using this in the bottom less listing fashion, am I supposed to make some changes in AJAX part (or load_more.php) as well? Sorry but I am not good in AJAX - hence this silly question.
Thanks / Regards to all for your kind help and suggestions.
Change the line:
$sql = 'SELECT * FROM agency_list WHERE id > :last_id ORDER BY id DESC LIMIT 0, :limit';
$sql = 'SELECT * FROM agency_list WHERE id < :last_id ORDER BY id DESC LIMIT 0, :limit';
All you have to do is change this operator: > to <
I am trying to create a paragraph and next to that paragraph are images that are generated randomly from a database table. The main container is called ".container" and this includes every element. .container is set to width: 90%. The paragraph (.header) floats to the left and has a width of 70%. The generated images (.recommend) floats to the right and has a width of 30%. Everything works out fine, but the only problem is that when I set the images to take up the whole space of the .recommend div (width: 100%), but it doesn't do that. Instead, the width of the images are 30%. How do I make the images take up the whole space of the .recommend div?
<!DOCTYPE html>
<html>
<head><link type="text/css" rel="stylesheet" href="/science/template.css"></head>
<body>
<div class="container">
<div class="header">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="recommend">
<?php
$numArray = array();
for ($i = 1; $i <=10; $i++)
{
$numArray[$i] = $i;
}
shuffle($numArray);
$resultSet = $db->query("SELECT * FROM table");
if ($resultSet->num_rows != 0)
{
while ($rows = $resultSet->fetch_assoc())
{
$id = $rows["id"];
$image1 = $rows["image1"];
$image2 = $rows["image2"];
$image3 = $rows["image3"];
$title = $rows["title"];
$title2 = $rows["title2"];
$title3 = $rows["title3"];
echo "<div class=row>";
if ($id == $numArray[0])
{
echo "<div class=col-md-4 id=left><img src=$image1><p>$title</p></div>";
}
if ($id == $numArray[1])
{
echo "<div class=col-md-4 id=left><img src=$image1><p>$title</p></div>";
}
if ($id == $numArray[2])
{
echo "<div class=col-md-4 id=left><img src=$image1><p>$title</p></div>";
}
echo "</div>";
}
}
?>
</div>
</div>
</body>
</html>
CSS
.container{
background--color: green;
width: 90%;
height: auto;
}
.header{
background-color: blue;
float: left;
width: 70%;
}
.recommend{
background-color: red;
width: 30%;
float: right;
}
.recommend img{
width: 100%;
}
It would be FAR more useful to see the rendered HTML than the PHP that generates the html.
The image is taking the full width of the containing div - which is set to 30% width. This markup: <div class=col-md-4 id=left> is using a Bootstrap grid class. And, col-md-4 tells the div to be 4/12 (or 30%) of the width of the parent. Since the parent is .recommend, then the div is 30%, and the image inside is 100% of THAT (which means it is 30% of the .recommend div)
So, you can either remove the col-md-4 class from the divs, or you can try and resolve it another way.
According to the CSS provided .recommend div is set to width:30%
All the child elements that have width:100% (images) will only take up as much space as .recommend div, which is 30%
I have 3 web pages with the same code within a website. I am having success with 2 of my 3 pages. The ckeditor instances update as expected.
I have finally figured out "what the issue is", BUT still don't know how to fix it. It seems that if I type only one line of code and click out of the div (ie. blur event happens) it saves as is expected. If I hit a hard return and type other text the blur event won't save ANYTHING after the hard return. Seems to be a bug in this version of CKEDITOR. As I mentioned, I have 2 other pages with exactly the same code and everything works just fine.
<?php
session_start();
$thisPage = "services";
require('functions.php');
include('header.htm');
?>
<title>Services | Dr. Your Name</title>
<style type="text/javascript">
#cke_body {margin-left:120px;margin-top:30px;width:520px;background-color:gray;}
</style>
<script type="text/javascript">
CKEDITOR.config.filebrowserBrowseUrl= 'browser/browseAdminUploads.php';
CKEDITOR.config.extraPlugins = 'justify';
</script>
</head>
<body>
<div id="header" class="clear">
<div id="headerContent">
<?php include ("bannerIcons.php"); ?>
<div id="logo">
<img src="images/logo.png" title="home" alt=""/>
</div> <!--end logo-->
<?php include('mainMenu.php');?>
</div>
</div> <!--end header-->
<div id="container">
<div id="content" class="shadow"><div class="content">
<div id="colLt"><div class="content">
<?php
connect();
$sql = mysql_query("SELECT services FROM contentAreas") or die("nothing found");
$row = mysql_fetch_assoc($sql);
if ($_SESSION['username']=='admin'){
echo "<div id='services' contenteditable='true' onblur='saveServices()'>";
} else {
echo "<div id='services'>";
}
echo $row['services'];
echo "</div>";?>
<script type="text/javascript">
function saveServices() {
var data = CKEDITOR.instances.services.getData();
$.post('saveServices.php', {services:data})
}
</script>
</div></div>
<?php include('saveServices.php');?>
<div id="colRt"><div class="content">
<div id="serviceBox" class="shadow"><div class="content">
<p class="big italTxt">one or more testimonials could go here. Lorem ipsum dolor sit amet, mel cu atqui perfecto, nec te vero fugit denique, an vel mundi tritani concludaturque.<br><br>Laoreet erroribus eos no. Eu nec maluisset repudiandae. Possit lucilius constituam his cu, quas liber sea an, eum purto errem audire eu. In viris assentior vis, pri iudico dolorem electram ne, ea ius scripta virtute.</p>
</div></div>
</div></div><!--end colRt-->
</div></div><!--end content-->
<div id="footer">
<?php include("footer.htm") ?>
</div><!--end footer-->
<div class="clear"></div>
</div><!--end container-->
<div class="clear"></div>
</body>
</html>
My file saveServices.php is as follows:
<?php
$services=$_POST['services'];
echo "hello<br>";
echo "services: ".$services;
include('functions.php');
connect();
$sql1 = mysql_query("UPDATE contentAreas SET services = '$services'") or die ("Your information has not been posted");
?>
Thanks again for your help!
I can't believe this nor do I understand it, but when I changed my div name from "services" to "offers", it worked. Is services a reserve word? Could my function name saveServices() be too long? I would love to hear a concrete explanation about why this has happened.
Also, I upgraded from 4.0.2 standard to 4.2.2 standard.