Questions PHP Images into Bootstrap Thumbnails show - php

Help i uses this code PHP and bootstrap please see image.
<?php
$sql = "SELECT * FROM article ORDER BY article_id DESC";
$r = page_query($link, $sql, 10);
while ($a = mysqli_fetch_array($r)) {
$src = "images/cover-image.jpg";
if ($a['image_id'] != 0) {
$src = "read-image.php?id={$a['image_id']}";
}
echo '
<div class="row">
<div class="col-lg-3 col-sm-6">
<div class="thumbnail">
<div class="thumb">
<img src="' . $src . '" alt="">
<div class="caption-overflow">
<span>
<i class="icon-plus3"></i>
<i class="icon-link2"></i>
</span>
</div>
</div>
<div class="caption">
<h6 class="no-margin-top text-semibold">
Not rapturous
<i class="icon-download pull-right"></i>
</h6>
' . mb_substr($a['article_text'], 0, 120, 'utf-8') . '...<br>' . '
</div>
</div>
</div>';
}
if (page_total() > 1) {
echo '<p id="page">';
page_echo_pagenums();
echo '</p>';
}
?>
Image
I use this code PHP and bootstrap see images
The problem of this sort on the part of the how to had to modify how it displays the correct result.

What I found Is:
You opened <div class="row">. But, not closed. (It may be one of the reason for alignment not coming properly)
And, My suggestion is not to use <div class="row"> inside while loop. Place it above while loop. Because every occurrence in while loop, it will take single row as whole div. Putting it before while loop, it will help you to place all col-lg-3 rows inside <div class="row"> in proper alignment.
Updated Code:
<div class="row">
<?php
$sql = "SELECT * FROM article ORDER BY article_id DESC";
$r = page_query($link, $sql, 10);
while ($a = mysqli_fetch_array($r)) {
$src = "images/cover-image.jpg";
if ($a['image_id'] != 0) {
$src = "read-image.php?id={$a['image_id']}";
}
echo '
<div class="col-lg-3 col-sm-6">
<div class="thumbnail">
<div class="thumb">
<img src="' . $src . '" alt="">
<div class="caption-overflow">
<span>
<i class="icon-plus3"></i>
<i class="icon-link2"></i>
</span>
</div>
</div>
<div class="caption">
<h6 class="no-margin-top text-semibold">
Not rapturous
<i class="icon-download pull-right"></i>
</h6>
' . mb_substr($a['article_text'], 0, 120, 'utf-8') . '...<br>' . '
</div>
</div>
</div>';
}
?>
</div>
When, I did these changes in my desktop. It works fine for me. Keep calm. Have patience. And, Try once again. It will work.

Related

class row in style.php

Im working on a article:
I want 3 in one row. I know how to do it with stype, but i dont know how to do it with style.php.
enter image description here
This is only the part of code but I need to properly implement grid:
echo '<div class="container">';
echo '<div class="row padding">';
echo '<div class="col-md-4 col-sm-12">';
echo '<div class="card">';
echo '<img src="' . UPLPATH . $row['slika'] . '"';
echo '<div class="card-body">';
echo '<h6 class="card-title">';
echo '«';
echo $row['naslov'];
//style.php
<?php
header('content-type:text/css');
$grid='grid';
?>
.container {
display: <?=$grid?>;
}
Well, you are dealing the problem really improperly.
I don't really get why you need to use a variable named $grid while you can directly pass the grid attribute to your .container.
You don't have do complicate it like this.
What I would do in your case would be the next thing:
I would create a class named .grid like:
.grid {
display: grid !important;
}
As for the rest I would put it like this:
Please provide more info as regards how you extract out the $row variable data.
The layout per se, would have to be like this in order for you to have 3 cards in a row. Hope that helps you. Cheers
<div class="container grid">
<div class="row padding">
<div class="col-md-12 col-sm-12">
<div class="col-md-4 col-sm-4">
<div class="card">
<img src="<?= '"'. UPLPATH . $row['slika'] . '"' alt="whatever
you need" />
<div class="card-body">
<h6 class="card-title">
<?php echo '«' . " ". $row['naslov']; ?>
</h6>
</div>
</div>
</div>
<div class="col-md-4 col-sm-4">
<div class="card">
<img src="<?= '"'. UPLPATH . $row['slika'] . '"' alt="whatever
you need" />
<div class="card-body">
<h6 class="card-title">
<?php echo '«' . " ". $row['naslov']; ?>
</h6>
</div>
</div>
</div>
<div class="col-md-4 col-sm-4">
<div class="card">
<img src="<?= '"'. UPLPATH . $row['slika'] . '"' alt="whatever
you need" />
<div class="card-body">
<h6 class="card-title">
<?php echo '«' . " ". $row['naslov']; ?>
</h6>
</div>
</div>
</div>
</div>
</div>

Use exploded array as a list within a while loop

I got a while loop that shows some old data. I recently added a new tablerow to the database that contains a string thats exploded into an array at every comma.
I then use a for loop to show the array values into a list and use the variable that contains the list in the echoed while loop data.
My code (only relevant parts):
while($row_items = mysqli_fetch_array($res_items, MYSQLI_ASSOC)) {
if($row_items['checkpoints'] != ''){
$check = explode(',', $row_items['checkpoints']);
}else{
$check = '';
}
foreach($check as $list){
$checklist .= '<li>'.$list.'</li>';
}
echo '
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-6 portf">
<a class="fancybox" href="../../catalogus/'.$row_items['afbeelding'].'">
<div class="gallery-item">
<div class="image">
<img src="../../catalogus_icons/'.$row_items['afbeelding'].'.jpg" alt="" style="border:1px solid #ccc;" class="img-responsive" />
</div>
<div class="bottom-info">
<div class="name">'.$row_items['naam'].'</div>
<div>'.$checklist.'</div>
<button class="contact_button buttoncontact btn-primary" style="border-radius:2px;">
Contact
<span class="icon-mail-alt"></span>
</button>
</div>
</div>
</a>
</div>';
}
But this shows the same list on every div output (while loop result). I added 1 list to test, and it adds that list to every item, not only the item that has a list. How can I make sure it only adds the list to the correct result?
$row_items['checkpoints']; contains: 'goedkoop,snel,test'
It's likely because you are not clearing the $checklist variable between iterations of the loop. You are simply adding to the same list every iteration.
while ($row_items = mysqli_fetch_assoc($res_items)) {
$checklist = '';
if ($row_items['checkpoints'] != '') {
$check = explode(',', $row_items['checkpoints']);
foreach($check as $list) {
$checklist .= '<li>'.$list.'</li>';
}
}
echo '
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-6 portf">
<a class="fancybox" href="../../catalogus/'.$row_items['afbeelding'].'">
<div class="gallery-item">
<div class="image">
<img src="../../catalogus_icons/'.$row_items['afbeelding'].'.jpg" alt="" style="border:1px solid #ccc;" class="img-responsive" />
</div>
<div class="bottom-info">
<div class="name">'.$row_items['naam'].'</div>
<div>'.$checklist.'</div>
<button class="contact_button buttoncontact btn-primary" style="border-radius:2px;">
Contact
<span class="icon-mail-alt"></span>
</button>
</div>
</div>
</a>
</div>';
}

Using information in an SQL array to provide a result in a different field

I'm trying to display the gang name of a user if their steam id is found in the list of players.
Gang Table
I can get other details to pull but this is the first time I have tried to pull from an array.
<div class="col-lg-3 col-md-6">
<div class="panel panel-yellow">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-users fa-2x"></i>
</div>
<div class="col-xs-9 text-right">
<?php
$sid = $steamprofile['steamid'];
$bob = ("[`$sid`]");
$sql = "SELECT `name` FROM `gangs` WHERE `members` = (' . explode(',', $bob) . ')";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
echo "<div class='big'>" . $row["name"] . "</div>";
};
?>
</div>
</div>
</div>
<a href="#">
<div class="panel-footer">
<span class="pull-left">Gang Management</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
Your member column seems to be a JSON array text field. You can't directly search within it unless you use TEXT search methods.
$query = 'select * from users where members LIKE "%\"' . $steamId . '\"%"';

Reduce text that is displayed from the database

On the first page I want to limit the $row['opis'] to 100 chars, but user have possibility to type 500 chars, so I need to limit $row['opis'] in first page. How can I do this?
This is my code:
<?php
mysql_connect("localhost","root","123") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$strSQL = "SELECT * FROM table_name ORDER BY id DESC";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo '<div class="col-md-3 col-sm-6 masonry-grid-item">
<div class="listing-item">
<div class="overlay-container">
<img src="images/product-1.png" alt="">
<a href="oglas/index.php?id=' . $row['id'] . '" class="overlay small">
<i class="fa fa-plus"></i>
<span>View Details</span>
</a>
</div>
<div class="listing-item-body clearfix">
<h3 class="title">'. $row['naziv'] .'</h3>
<p>' . $row['opis'] . '</p>
<span class="price">' . $row['tel'] . '</span>
<div class="elements-list pull-right">
<i class="fa fa-heart-o"></i>
Pogledaj
</div>
</div>
</div>
</div>';
}
mysql_close();
?>
Thanks!
You can use mb_strimwidth, to show first 100 characters
<?php
mysql_connect("localhost","root","123") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$strSQL = "SELECT * FROM table_name ORDER BY id DESC";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo '<div class="col-md-3 col-sm-6 masonry-grid-item">
<div class="listing-item">
<div class="overlay-container">
<img src="images/product-1.png" alt="">
<a href="oglas/index.php?id=' . $row['id'] . '" class="overlay small">
<i class="fa fa-plus"></i>
<span>View Details</span>
</a>
</div>
<div class="listing-item-body clearfix">
<h3 class="title">'. $row['naziv'] .'</h3>
<p>' . mb_strimwidth($row["opis"], 0, 100, "") . '</p>
<span class="price">' . $row['tel'] . '</span>
<div class="elements-list pull-right">
<i class="fa fa-heart-o"></i>
Pogledaj
</div>
</div>
</div>
</div>';
}
mysql_close();
?>
Explanation:
mb_strimwidth($YOUR_STRING, 0, 100, "")
0 means that the trim starts from the first character, and 100 is the limit of characters. Fourth option allows you to add something like "..." at the end of the new string.
Edit
You can also use substr but it is counting using bytes, and not characters. So if you are using some multi-byte encoding, like UTF-8 (Greek, Serbian, Romanian etc), you should use mb_strimwidth as above.
NETCreator Thanks a lot!
Answer is add mb_strimwidth($YOUR_STRING, 0, 100, "")...
<?php
mysql_connect("localhost","root","123") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$strSQL = "SELECT * FROM table_name ORDER BY id DESC";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo '<div class="col-md-3 col-sm-6 masonry-grid-item">
<div class="listing-item">
<div class="overlay-container">
<img src="images/product-1.png" alt="">
<a href="oglas/index.php?id=' . $row['id'] . '" class="overlay small">
<i class="fa fa-plus"></i>
<span>View Details</span>
</a>
</div>
<div class="listing-item-body clearfix">
<h3 class="title">'. $row['naziv'] .'</h3>
<p>' . mb_strimwidth($row["opis"], 0, 100, "") . '</p>
<span class="price">' . $row['tel'] . '</span>
<div class="elements-list pull-right">
<i class="fa fa-heart-o"></i>
Pogledaj
</div>
</div>
</div>
</div>';
}
mysql_close();
?>
You can use substr also.. the below code display first 4 characters.
echo substr('abcdef', 0, 4);
output
abcd
#Mile you can do like this to
$text = substr($text,$start,$length);
here $text is your string, $start is your starting point and $length is how long you want to show a string.

bootstrap 2.3 multiple images / items in carousel

I am working on a PHP based website which is using Twitter Bootstrap 2. I am pulling the users from MySQL database and trying to display them in multiple frames/items of carousel on a screen rather than a single item using while loop.
This is what my carousel looks like at present, as you will notice user 5 is not supposed to appear the way it is right now and is only supposed to appear when i click on arrow on right side of the carousel.
This is what my php code looks like
<div class="carousel slide" id="myCarousel">
<h4 class="carousel-title">Text title</h4>
<div class="carousel-inner">
<?php
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
?>
<div class="item active">
<div class="span3 mef-3">
<div class="about portrait">
<div class="tooltip-demo">
<a href="#" rel="tooltip" data-placement="top" data-toggle="tooltip"
data-title="">
<img class="img-circle" width="180" height="200" data-src="holder.js/360x270"
alt="270x280"
style="" src="assets/img/adviser.png"></a>
</div>
<div class="caption">
<h3 class="name" style="text-align: center"><?php echo $row['fname']." ".$row['lname'] ?></h3>
<p style="text-align: center">
Specialities</p>
</div>
<div class="mefradio">
<input type="radio" name="adviser" id="adviser" value='<?php echo $row['user_id']."|".$row['fname']." ".$row['lname'] ?>'><br>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<a data-slide="prev" href="#textCarousel" class="left carousel-control">‹</a>
<a data-slide="next" href="#textCarousel" class="right carousel-control">›</a>
</div>
I will really appreciate any guidance on how to get it to work
UPDATE
This is the updated code that is working, thanks to #I can Has Kittenz
<div class="carousel slide" id="myCarousel">
<h4 class="carousel-title">Text title</h4>
<div class="carousel-inner">
<?php
$i = 1;
$next_item = true;
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
if ($i == 1) {
echo '<div class="item active">';
} elseif ($next_item == true) {
echo '<div class="item">';
}
?>
<div class="span3 mef-3">
<div class="about portrait">
<div class="tooltip-demo">
<a href="#" rel="tooltip" data-placement="top" data-toggle="tooltip"
data-title="">
<img class="img-circle" width="180" height="200" data-src="holder.js/360x270"
alt="270x280"
style="" src="assets/img/adviser.png"></a>
</div>
<div class="caption">
<h3 class="name"
style="text-align: center"><?php echo $row['fname'] . " " . $row['lname'] ?></h3>
<p style="text-align: center">
Specialities</p>
</div>
<div class="mefradio">
<input type="radio" name="adviser" id="adviser"
value='<?php echo $row['user_id'] . "|" . $row['fname'] . " " . $row['lname'] ?>'><br>
</div>
</div>
</div>
<?php
$next_item = false;
if ($i % 4 == 0) {
echo '</div>';
$next_item = true;
}
$i++;
}
?>
</div>
<a data-slide="prev" href="#myCarousel" class="left carousel-control">‹</a>
<a data-slide="next" href="#myCarousel" class="right carousel-control">›</a>
</div>
The JS that needs to go with this is as following
<script>
$(document).ready(function(){
$('#myCarousel').carousel({
pause: true,
interval: false
});
});
$('#myCarousel').on('slid', '', function() {
var $this = $(this);
$this.find('.carousel-control').show();
if($('.carousel-inner .item:first').hasClass('active')) {
$this.find('.left.carousel-control').hide();
} else if($('.carousel-inner .item:last').hasClass('active')) {
$this.find('.right.carousel-control').hide();
}
});
</script>
Updated:
As per the way Bootstrap 2.3 carousel works, multiple items like the way you have done won't show 4 items in a row and only one .item class can have an .active class to it, so here's what we would do:
<div class="item active">
<div class="span3"><img></div>
<div class="span3"><img></div>
<div class="span3"><img></div>
<div class="span3"><img></div>
</div>
<div class="item">
<div class="span3"><img></div>
<div class="span3"><img></div>
<div class="span3"><img></div>
<div class="span3"><img></div>
</div>
That's how we are going to structure your elements to look like. So code in:
<!-- code follows -->
<div class="carousel-inner">
<?php
$i = 1;
$next_item = true;
while ($i < 10)
{
if ($i == 1)
{
echo '<div class="item active">';
}
elseif ($next_item == true)
{
echo '<div class="item">';
}
?>
<div class="span3 mef-3">
<!-- code follows -->
</div>
<?php
$next_item = false;
if ($i % 4 == 0)
{
echo '</div>';
$next_item = true;
}
$i++;
}
?>
Also, since you name your carousel as id=myCarousel, your prev and next button's href should be href="#myCarousel" and not href="#textCarousel".
Here's a demo of what it looks like.

Categories