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.
Related
i'm new to web development; I have been trying to populate bootstrap pills dynamically from the database, generating the pill itself and also the content dynamically. So far only the Pills are being generated but the contents don't seem to be generated. The pills are meant to display contents that are individual pdf files obtained from the database sorted based on the category matching the pill being iterated in the while loop. Here is my code. Thanks.
//HTML Bootstrap
<div class="row bd-sidebar">
<div class="col-2 border-right">
<h3 class="pl-2">Categories</h3><hr>
<div class="nav flex-column nav-pills overflow-auto" id="v-nav-tab" role="tablist" aria-orientation="vertical">
<?php include_once '.assets/_server/category_data.php'; ?>
<?php echo $category_menu; ?>
<div class="col-10">
<div class="tab-content" id="v-pills-tabContent">
<?php echo $category_content;?>
</div>
</div>
</div>
</div>
</div>
//category_data.php
<?php
include_once("dbConfig.php");
$query = "SELECT * FROM `categories` GROUP BY `categoryName` ";
$categoryResult = mysqli_query($link, $query);
$category_menu = "";
$category_content = "";
$count = 0;
while($row = mysqli_fetch_array($categoryResult)){
$value = $row['categoryId'];
$categoryName = $row['categoryName'];
if($count == 0){
$category_menu .= '
<a class="nav-link active" id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade show active" id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="row">
';
}else{
$category_menu .= '
<a class="nav-link" id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade" id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="row">
';
}
$content_query = "SELECT * FROM `books` WHERE `categoryId` = '.$value.' GROUP BY `file_name`";
$content_result = mysqli_query($link, $content_query);
while($sub_row = mysqli_fetch_array($content_result)){
$category_content .= '
</div>
<div class="col-1">
<a class="material text-secondary text-decoration-none" href=".assets/pdf.js/web/viewer.html?file=materials/'.$sub_row['file_name'].'" data-toggle="tooltip" data-delay="300" data-animation="" data-html="true" title="'.$sub_row['file_name'].'">
<div class="mycard justify-content-center" style="width: 7rem;">
<img style="width: 70px; height: 70px;" src="img/book-thumbs/pdf_ico.png" class="mx-auto d-block" alt="pdf thumbnail">;
<div class="bookcardTitle">
<p class="text-center" id="bookcardTitle">'.$sub_row['file_name'].'</p>
</div>
</div>
</a>
</div>
';
}
$category_content .= '<div style="clear:both"></div></div></div>';
$count++;
}
?>
The immediate error in your code is the $content_query line:
$content_query = "SELECT * FROM `books` WHERE `categoryId` = '.$value.' GROUP BY `file_name`";
The string is quoted with double quotes but the $value part is surrounded by single quotes. The solution would be to replace the quotes:
$content_query = "SELECT * FROM `books` WHERE `categoryId` = ".$value." GROUP BY `file_name`";
You can see how the syntax highlight shows the error.
But there's a deeper problem here regarding sql injection. You should not concatenate values obtained from somewhere else in a query. Please see this question: How can I prevent SQL injection in PHP? and this website: https://phpdelusions.net/sql_injection for more information.
<?php
include_once("dbConfig.php");
$query = "SELECT * FROM `categories` GROUP BY `categoryName` ";
$categoryResult = mysqli_query($link, $query);
$category_menu = "";
$category_content = "";
$count = 0;
while($row = mysqli_fetch_array($categoryResult)){
$value = $row['categoryId'];
$categoryName = $row['categoryName'];
if($count == 0){
$category_menu .= '
<a class="nav-link " id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade " id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="nav justify-content-center navbar-light bg-light">
<form class="form-inline v-pills-search" action="">
<input class="form-control rounded-pill mr-2" type="search" name="query" id="book_query" placeholder="Search...">
<button class="btn rounded-pill btn-outline-primary my-2 my-sm-0" type="submit"><i class="fas fa-search"></i></button>
</form>
</div>
<div class="row">
';
}else{
$category_menu .= '
<a class="nav-link" id="v-pills-'.$value.'-tab" data-toggle="pill" href="#v-pills-'.$value.'" role="tab" aria-controls="v-pills-'.$value.' aria-selected="false">'.$categoryName.'</a>
';
$category_content .= '
<div class="tab-pane fade" id="v-pills-'.$value.'" role="tabpanel" aria-labelledby="v-pills-'.$value.'-tab">
<div class="nav justify-content-center navbar-light bg-light">
<form class="form-inline v-pills-search" action="">
<input class="form-control rounded-pill mr-2" type="search" name="query" id="book_query" placeholder="Search...">
<button class="btn rounded-pill btn-outline-primary my-2 my-sm-0" type="submit"><i class="fas fa-search"></i></button>
</form>
</div>
<div class="row">
';
}
$content_query = "SELECT * FROM `books` WHERE `categoryId` = '".$row['categoryId']."' GROUP BY `file_name`";
$content_result = mysqli_query($link, $content_query);
if(mysqli_num_rows($content_result) < 0) {
$conRow_html .= '<br>No items found in this category!';
}
while($sub_row = mysqli_fetch_array($content_result)){
$category_content .= '
<div class="col-1 mr-4">
<a class="material text-secondary text-decoration-none" href=".assets/pdf.js/web/viewer.html?file=materials/'.$sub_row['file_name'].'" data-toggle="tooltip" data-delay="0" data-animation="true" data-html="true" title="'.$sub_row['file_name'].'">
<div class="mycard justify-content-center" style="width: 7rem;">
<img style="width: 70px; height: 70px;" src="img/book-thumbs/pdf_ico.png" class="mx-auto d-block" alt="pdf thumbnail">
<div class="bookcardTitle">
<p class="text-center book_name" id="bookcardTitle">'.$sub_row['file_name'].'</p>
</div>
</div>
</a>
</div>
';
}
$category_content .= '<div class="clear:both"></div></div></div>';
$count++;
}
?>
I'm doing about the blog webpage. User can post their status on the blog, so on user profile page, user can review what they posted.
I had meet the problem about the post section and comment section which are seperated.
What I wanted is to display the comment section with the post section.The comment section is display according to the post section.
Example: like facebook, I post a status, and other user comment on that post.
Img 1 is below:
On Img 1, you can see the comment section is not display according to the post section.
Img 2 is below:
This is the example what I want to do.
PHP & HTML code is below:
<div class="feed-card">
$postSql = "SELECT user.firstname, user.lastname, user.profile_photo, post.id ,post.post_contain, post.post_image, post.timestamp
FROM user
INNER JOIN post
ON user.id = post.user_id
WHERE user.id = '".$u_id."'
ORDER BY post.timestamp
DESC";
if ($postStmt = $conn->prepare($postSql)) {
/* execute query */
$postStmt->execute();
$postStmt->bind_result($user_firstname, $user_lastname, $user_profile_photo, $post_id, $post_content, $post_image, $post_timestamp);
$postIdArray = array();
while ($postStmt->fetch()) {
echo "post id: $post_id post content: $post_content";
echo '
<div class="media">
<div class="media-left">
<a class="media-object p-t-5">
<img src="' . $user_profile_photo . '" class="img-rounded custom-birthday-image" /></img>
</a>
</div>
<div class="media-body">
<h4 class="media-heading">
' . $user_firstname . ' ' . $user_lastname . '
</h4>
<small class="timestamp">' . $post_timestamp . '</small>
<p>' . $post_content . '</p>
</div>
<div class="comment-tools ml35">
<ul>
<li id="' . $post_id . '"><img src="/img/ic_like.png">Like</li>
<li id="' . $post_id . '"><img src="/img/ic_comment-no-apply.png"><span class="unselect">Comment</span></li>
<li id="' . $post_id . '"><img src="/img/ic_noapplyshare.png"><span class="unselect">Share</span></li>
</ul>
</div>
</div>
';
$postIdArray[] = $post_id;
}
$postStmt->close();
foreach ($postIdArray as $value){
getComments($conn,$value);
}
}
function getComments($conn,$postId){
$commentSql = " SELECT id, user_id, user_desc, timestamp FROM comments WHERE post_id = ? ";
if($commentStmt = $conn->prepare($commentSql)){
$commentStmt->bind_param("i", $postId);
$commentStmt->execute();
$commentStmt->bind_result($commentId, $userId, $userComment, $comment_timestamp);
while ($commentStmt->fetch()) {
// echo "user dec: $userComment comment id: $commentId";
echo '
<div class="panel panel-radius">
<div class="panel-heading panel-custom-event custom-donut">
<p><img src="/img/people_liked.png">
</p>
</div>
<div class="panel-body body-panel no-border">
<hr class="custom-hr">
<div class="media-left">
<a href="#">
<img src="' . $row->profile_photo . '" class="img-rounded custom-birthday-image" /></img>
</a>
</div>
<div class="media-body">
<h4 class="media-heading"> ' . $row->firstname . ' ' . $row->lastname . '</h4>
<p>' . $userComment . '</p>
<div class="comment-tools">
<ul id="c_option">
<li id="c_like" value="' . $commentId . '">Like</li>
<li id="" value="' . $commentId . '"><a href="" onclick="return false;"><span class="unselect" id="comment_reply">Reply</span></li>
<li id="" value="' . $commentId. '"><img src="/img/people_liked.png"></li>
<li>
<small class="timestamp">' . $comment_timestamp . '</small>
</li>
</ul>
</div>
</div>
<div class="media m-b-20">
<div class="media-left">
<a href="#">
<img src="' . $user_profile_photo . '" class="reply_image" /></img>
</a>
</div>
<div class="media-body">
<div class="right-addon">
<input type="text" class="form-control addradius" id="reply">
</div>
</div>
</div>
</div>
</div>
';
}
$commentStmt->close();
return $userComment;
}else{
return "error preparing sql";
}
}
Instead of collecting all the post ids in an array and then fetch the comments for each, fetch the comments for each post as you are displaying the posts. I have not been able to test the code but this should work.
<div class="feed-card">
<?php
$postSql = "SELECT user.firstname, user.lastname, user.profile_photo, post.id ,post.post_contain, post.post_image, post.timestamp
FROM user
INNER JOIN post
ON user.id = post.user_id
WHERE user.id = '".$u_id."'
ORDER BY post.timestamp
DESC";
if ($postStmt = $conn->prepare($postSql)) {
/* execute query */
$postStmt->execute();
$postStmt->bind_result($user_firstname, $user_lastname, $user_profile_photo, $post_id, $post_content, $post_image, $post_timestamp);
$postIdArray = array();
while ($postStmt->fetch()) {
echo "post id: $post_id post content: $post_content";
echo '
<div class="media">
<div class="media-left">
<a class="media-object p-t-5">
<img src="' . $user_profile_photo . '" class="img-rounded custom-birthday-image" /></img>
</a>
</div>
<div class="media-body">
<h4 class="media-heading">
' . $user_firstname . ' ' . $user_lastname . '
</h4>
<small class="timestamp">' . $post_timestamp . '</small>
<p>' . $post_content . '</p>
</div>
<div class="comment-tools ml35">
<ul>
<li id="' . $post_id . '"><img src="/img/ic_like.png">Like</li>
<li id="' . $post_id . '"><img src="/img/ic_comment-no-apply.png"><span class="unselect">Comment</span></li>
<li id="' . $post_id . '"><img src="/img/ic_noapplyshare.png"><span class="unselect">Share</span></li>
</ul>
</div>
</div>
';
//$postIdArray[] = $post_id;
getComments($conn,$post_id);
}
$postStmt->close();
//foreach ($postIdArray as $value){
// getComments($conn,$value);
//}
}
function getComments($conn,$postId){
$commentSql = " SELECT id, user_id, user_desc, timestamp FROM comments WHERE post_id = ? ";
if($commentStmt = $conn->prepare($commentSql)){
$commentStmt->bind_param("i", $postId);
$commentStmt->execute();
$commentStmt->bind_result($commentId, $userId, $userComment, $comment_timestamp);
while ($commentStmt->fetch()) {
// echo "user dec: $userComment comment id: $commentId";
echo '
<div class="panel panel-radius">
<div class="panel-heading panel-custom-event custom-donut">
<p><img src="/img/people_liked.png">
</p>
</div>
<div class="panel-body body-panel no-border">
<hr class="custom-hr">
<div class="media-left">
<a href="#">
<img src="' . $row->profile_photo . '" class="img-rounded custom-birthday-image" /></img>
</a>
</div>
<div class="media-body">
<h4 class="media-heading"> ' . $row->firstname . ' ' . $row->lastname . '</h4>
<p>' . $userComment . '</p>
<div class="comment-tools">
<ul id="c_option">
<li id="c_like" value="' . $commentId . '">Like</li>
<li id="" value="' . $commentId . '"><a href="" onclick="return false;"><span class="unselect" id="comment_reply">Reply</span></li>
<li id="" value="' . $commentId. '"><img src="/img/people_liked.png"></li>
<li>
<small class="timestamp">' . $comment_timestamp . '</small>
</li>
</ul>
</div>
</div>
<div class="media m-b-20">
<div class="media-left">
<a href="#">
<img src="' . $user_profile_photo . '" class="reply_image" /></img>
</a>
</div>
<div class="media-body">
<div class="right-addon">
<input type="text" class="form-control addradius" id="reply">
</div>
</div>
</div>
</div>
</div>
';
}
$commentStmt->close();
return $userComment;
}else{
return "error preparing sql";
}
}
?>
</div>
I have following problem. I need to create pagination for this results. For create pagination I need to have only one while cycle (one sql query). Now I have three queries because of responsive div. I need preserve these three divs. Any ideas?
Thank you.
<div class="col-md-4 col-sm-12">
<?php
require 'db.php';
mysql_query("SET NAMES utf8");
$query = "SELECT * FROM dot where schva=1 order by id desc";
$result = mysql_query($query) or die(mysql_error());
$item_num = 0;
$num_records = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
if ($item_num % 3 == 0) {
echo '<div class="box1 space30">
<div class="media">
<div class="media-left">
<a href="dot/' . $row['id'] . '">
<img src="img/chat.png" alt="...">
</a>
</div>
<div class="media-body">
<p>' . $row['text'] . '</p>
</div>
</div>
<div class="divider space20"></div>
<div class="txt">
<p>' . $row['nad'] . '</p>
</div>
</div>';
} ?>
<?php
$item_num++;
}
?>
</div>
<div class="col-md-4 col-sm-12">
<?php
require 'db.php';
$query = "SELECT * FROM dot where schva=1 order by id desc";
$result = mysql_query($query) or die(mysql_error());
$item_num = 0;
$num_records = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
if ($item_num % 3 == 1) {
echo '<div class="box1 space30">
<div class="media">
<div class="media-left">
<a href="dot/' . $row['id'] . '">
<img src="img/chat.png" alt="...">
</a>
</div>
<div class="media-body">
<p>' . $row['text'] . '</p>
</div>
</div>
<div class="divider space20"></div>
<div class="txt">
<p>' . $row['nad'] . '</p>
</div>
</div>';
} ?>
<?php
$item_num++;
}
?>
</div>
<div class="col-md-4 col-sm-12">
<?php
require 'db.php';
$query = "SELECT * FROM dot where schva=1 order by id desc";
$result = mysql_query($query) or die(mysql_error());
$item_num = 0;
$num_records = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
if ($item_num % 3 == 2) {
echo '<div class="box1 space30">
<div class="media">
<div class="media-left">
<a href="dot/' . $row['id'] . '">
<img src="img/chat.png" alt="...">
</a>
</div>
<div class="media-body">
<p>' . $row['text'] . '</p>
</div>
</div>
<div class="divider space20"></div>
<div class="txt">
<p>' . $row['nad'] . '</p>
</div>
</div>';
} ?>
<?php
$item_num++;
}
?>
</div>
You can try this code, it's helpful. First use mysqli for query.
<div class="col-md-4 col-sm-12">
<?php
require 'db.php';
mysql_query("SET NAMES utf8");
$query = "SELECT * FROM dot where schva=1 order by id desc";
$result = mysql_query($query) or die(mysql_error());
$item_num = 0;
$num_records = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
if ($item_num % 3 == 0) {
//Code
}elseif($item_num % 3 == 1){
//Code
}elseif($item_num % 3 == 2){
//Code
}
$item_num++;
}
?>
</div>
Hope it will help.
$item_num = 0;
$num_records = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
if ($item_num % 3 == 0) {
echo '<div class="box1 space30">
<div class="media">
<div class="media-left">
<a href="dot/' . $row['id'] . '">
<img src="img/chat.png" alt="...">
</a>
</div>
<div class="media-body">
<p><a href="dot/' . $row['id'] . '"
style="color:white;">' . $row['text'] . '</a></p>
</div>
</div>
<div class="divider space20"></div>
<div class="txt">
<p>' . $row['nad'] . '</p>
</div>
</div>';
}elseif($item_num % 3 == 1){
echo '<div class="box1 space30">
<div class="media">
<div class="media-left">
<a href="dot/' . $row['id'] . '">
<img src="img/chat.png" alt="...">
</a>
</div>
<div class="media-body">
<p><a href="dot/' . $row['id'] . '"
style="color:white;">' . $row['text'] . '</a></p>
</div>
</div>
<div class="divider space20"></div>
<div class="txt">
<p>' . $row['nad'] . '</p>
</div>
</div>';
}elseif($item_num % 3 == 2){
echo '<div class="box1 space30">
<div class="media">
<div class="media-left">
<a href="dot/' . $row['id'] . '">
<img src="img/chat.png" alt="...">
</a>
</div>
<div class="media-body">
<p><a href="dot/' . $row['id'] . '"
style="color:white;">' . $row['text'] . '</a></p>
</div>
</div>
<div class="divider space20"></div>
<div class="txt">
<p>' . $row['nad'] . '</p>
</div>
</div>';
}
$item_num++;
}
?>
Or you can try by using PDO:
Version depends on the records in the database:
<?php
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $pdo->prepare("SELECT * FROM dot");
$sth->execute();
$data = $sth->fetchAll(PDO::FETCH_ASSOC);
?>
<?php $item_num = 0; ?>
<?php foreach ($data as $row): ?>
<div class="col-md-4 col-sm-12">
<?php if ($item_num % 3 == 0): ?>
<?php endif; ?>
<?php if ($item_num % 3 == 1): ?>
<?php endif; ?>
<?php if ($item_num % 3 == 2): ?>
<?php endif; ?>
<?php $item_num++; ?>
</div>
<?php endforeach; ?>
Version with a fixed amount of divs:
<?php
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $pdo->prepare("SELECT * FROM dot");
$sth->execute();
$data = $sth->fetchAll(PDO::FETCH_ASSOC);
?>
<?php for ($i = 0; $i < 3; $i++): ?>
<?php $item_num = 0; ?>
<div class="col-md-4 col-sm-12">
<?php foreach ($data as $row): ?>
<?php if ($item_num % 3 == 0): ?>
<?php endif; ?>
<?php if ($item_num % 3 == 1): ?>
<?php endif; ?>
<?php if ($item_num % 3 == 2): ?>
<?php endif; ?>
<?php $item_num++; ?>
<?php endforeach; ?>
</div>
<?php endfor; ?>
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.
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 . '\"%"';