I want to display images in same row,but i can display only under each other. I tried in css display: inline-block; but dont working. Any idea what i need to do? Thanks
The code for display images:
require_once 'dbConfig.php';
$result = $db->query("SELECT image FROM images ORDER BY uploaded DESC");
?>
<?php if($result->num_rows > 0){ ?>
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3" >
<a class="lightbox">
<?php while($row = $result->fetch_assoc()){
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'" width="250", " height="250">';}?>
<?php }else{ ?>
<p class="status error">Image(s) not found...</p>
<?php } ?>
</a>
</div>
</div>
It's because you large col is only 3.
Inspect element result
if you are using these images for lightbox thumbnail I would suggest d-flex rather than column system....
Try this code it will work .. now it will loop your columns as well
require_once 'dbConfig.php';
$result = $db->query("SELECT image FROM images ORDER BY uploaded DESC");
?>
<?php if($result->num_rows > 0){ ?>
<div class="row">
<?php while($row = $result->fetch_assoc()){
<div class="col-sm-6 col-md-4 col-lg-3" >
<a class="lightbox">
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'" width="250", " height="250">';}?>
</a>
</div>
<?php }else{ ?>
<p class="status error">Image(s) not found...</p>
<?php } ?>
</div>
Related
This is my code and I wanted to display an image from DB. I followed some videos and recommendations here on Stack Overflow, but still does not work.
Other values like description, title etc works, so the problem is not in the connection with the DB.
Thank you.
<?php
$sql= "SELECT * FROM guides WHERE id='$id'";
$result = mysqli_query($link, $sql);
$num = mysqli_num_rows($result);
if ($num > 0) {
$row = mysqli_fetch_assoc($result)
?>
<h1 class="title"><?=$row['title']?></h1>
<?php echo' <img class="header" style="height:400px" src="data:image/jpeg;base64,'.base64_encode( stripslashes($row['photo']) ).'" style="width:100px;"></img>' ?>
<div class="row">
<div class="leftcolumn">
<h2><?=$row['date']?></h2>
<div class="card" >
<div class="clearfix">
<p class="text" ><?=$row['description']?></p>
</div>
</div>
</div>
</div>
<?php
}
?>
I think you should try and specify the folder containing the given image also. E.g src = “containing_folder/$row[‘photo’]” and see if that works. You can still add your functions to the $row[‘photo’], this was just an example.
mysqli_fetch_assoc($result) this returns an array and you need to loop through the array:
The modified code given below----
$sql= "SELECT * FROM guides WHERE id='$id'";
$result = mysqli_query($link, $sql);
$num = mysqli_num_rows($result);
if ($num > 0) {
while($row = mysqli_fetch_assoc($result)){
?>
<h1 class="title"><?=$row['title']?></h1>
<?php echo' <img class="header" style="height:400px" src="data:image/jpeg;base64,'.base64_encode( stripslashes($row['photo']) ).'" style="width:100px;"></img>' ?>
<div class="row">
<div class="leftcolumn">
<h2><?=$row['date']?></h2>
<div class="card" >
<div class="clearfix">
<p class="text" ><?=$row['description']?></p>
</div>
</div>
</div>
</div>
<?php
}
}
?>
thanks for taking a look at my question.
I'm trying to get PHP to output bootstrap rows that only contain 2 col-md-6 columns, instead of outputting 1 row with 1 col for each iteration.
Searching here on Stackoverflow I found a solution that makes sense but when I implement it, the HTML that I get makes no sense!
I should be getting this:
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6"></div>
</div>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6"></div>
</div>
...But I'm getting this:
<div class="col-md-6">
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6"></div>
</div>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6"></div>
</div>
</div>
CODE:
<?php
require_once('somedb.php');
$query = mysqli_query($conn, "SELECT * FROM notyourbusiness");
$rowCount = mysqli_num_rows($query);
$i = 0;
echo '<div class="row">';
if($rowCount > 0){
while($row = mysqli_fetch_assoc($query)){
?>
<?php echo '<div class="col-md-6">'; ?>
<img src="img/project/<?php echo $row['thumb'] ?>" class="work-thumbnail" width="100">
<h2><?php echo $row["name"]; ?></h2>
<?php echo '</div>'; ?>
<?php
$i++;
if ($i%2 == 0) echo '</div><div class="row">';
} ?>
<?php } ?>
</div>
Any help will be greatly appreciated, thanks!
Can you provide us more information? It seems that the first is comming from outside of this php code.
You can try this
<?php
$query = mysqli_query($conn, "SELECT * FROM notyourbusiness");
$rowCount = mysqli_num_rows($query);
$i = 0;
if($rowCount > 0){
while($row = mysqli_fetch_assoc($query)){
$row_draw = ($i % 2 == 0) ? true : false;
# Start row div
if ($row_draw)
{
print "<div class='row'>";
}
# Print Column
print "<div class='col-md-6'>";
?>
<img src="img/project/<?php echo $row['thumb'] ?>" class="work-thumbnail" width="100">
<a href="javascript:void(0);">
<h2><?php echo $row["name"]; ?></h2>
</a>
<?php
print "</div>";
# End row div
if ($row_draw)
{
print "</div>";
}
$i++;
}
}
?>
I'm trying to populate data in a div. Which works fine except that, the first div of data will be repeated once as shown on the attached image. I couldn't see any logical error in my code, and hope someone could kindly help me.
<div class="posts">
<?php
include("dbconn.php");
$sql = "SELECT *
FROM posts p
INNER JOIN users u
ON p.userID=u.userID
INNER JOIN courses c
ON p.courseID=c.courseID;";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
?>
<section class="post">
<header class="post-header"> <img class="post-avatar" height="48" width="48" src="image/common/tilo-avatar.png">
<h2 class="post-title"><?php echo $row["postTitle"]; ?></h2>
<p class="post-meta"> By <?php echo $row["nickname"]; ?> under <a class="post-category post-category-design" href="#"><?php echo $row["courseName"]; ?></a> </p>
</header>
<div class="post-description">
<p> <?php echo $row["postContent"]; ?> </p>
</div>
</section>
<?php
}
} else {
echo "no questions yet";
}
?>
</div>
image
The search results should display like this
But my results are stacking on top of each.
Here is my code :
<div class="container">
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("thesis") or die(mysql_error());
$search = trim( $_POST['SearchKeywords']);
$query = " SELECT * FROM new_data WHERE Product_Title or Product_link LIKE'%$search%' ";
$sql = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($sql);
$count == 0;
if ($count == 0) {
echo "Sorry, Nothing Found !!";
}else{
while ($row = mysql_fetch_array($sql))
{
$img = $row ['Product_Img'];
$link = $row ['Product_link'];
$title = $row ['Product_Title'];
$price = $row ['Product_Price'];
?>
<div class="card">
<div class="front alert alert-success">
<?php echo "$title";
echo "<img src='$img' width='80px' height='100px'>";
echo "$price"; ?>
</div>
</div>
<?php
};
};
?>
</div> <!-- Container -->
Those div blocks are inside a container.
I added a bootstrap class in order for better a design.
You can use thumbnails with custom content
<div class="row">
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<h3>Thumbnail label</h3>
<p>...</p>
<p>Button Button</p>
</div>
</div>
</div>
</div>
I used a counter inside while loop.
Which will check, when there are already 4 blocks/ products in a single row then it will create a new row
<?php
if($productCount == 0)
{
echo "<div class='row'>"; }
}
$productCount++;
if($productCount==4)
{
echo "</div>" ;
$productCount = 0;
}
?>
I'm about to display comments on a page, everything works fine but I want to display the comments from the user first. So, how do I display the user comments from the user_id first? I'm using a while loop to display the comments.
I would be very grateful if anyone could help me. :)
<?php
$sql = "SELECT * FROM `comments` WHERE `post_id`=$pid AND `active`=1 ORDER BY ups-downs DESC";
$result = $mysqli->query($sql);
$count = $result->num_rows;
if($count == 1){
$counttext = "1 Comment";
}else{
$counttext = $count ." Comments";
}
?>
<div class="media-area media-area-small">
<h3 class="text-center"><?php echo $counttext; ?></h3>
<?php
while($row = $result->fetch_assoc()){
$uid = (int)$row["user_id"];
$user = get_user_info($mysqli,$uid);
?>
<div class="media">
<a class="pull-left" href="#">
<div class="avatar">
<img class="media-object" src="<?php echo $user["picture"]; ?>" alt="...">
</div>
</a>
<div class="media-body">
<table width="100%">
<tr valign="middle">
<td align="left"><h4 class="media-heading text-left"><?php echo fb_clear_name($mysqli, $user["id"]); ?></h4></td>
<td align="right"><h6 class="pull-right text-muted"><?php echo $row["ups"] - $row["downs"]; ?> bits</h6></td>
</tr>
</table>
<p><?php echo htmlentities($row["content"]); ?></p>
<div class="media-footer">
<i class="fa fa-reply"></i> Reply
<a href="#" class="pull-right text-muted">
<?php echo $row["timestamp"]; ?>
</a>
</div>
</div>
</div>
<?php
}
?>
Greetings
You can prefilter the data. For example use
$user_comments=array();
$other_comments=array();
while($row = mysql_fetch_assoc($result))
{
if($row['user']==$current_user)
{
$user_comments[]=$row;
}
else
{
$other_comments[]=$row;
}
}
$comments=array_merge($user_comments,$other_comments);
Then you can display the information the way you want to.