I want to display images in from server. In the database you can find the description and name of the image. the images should be displayed in a div where always the newest is on top. As the number of images increase so does the number of div's. so, the oldest will be at the bottom. I have read a number of posts and forums but I was unable to get the logic and the code on how to do it. I hope you can help me with my problem. Thanks a lot for your answer.
the only code i have is the formatting of the dive's:
<div class="gallery">
<div class= "group">
<div class="images">
</div>
<div class="details">
</div>
</div>
<div class= "group">
<div class="images">
</div>
<div class="details">
</div>
</div>
<div class= "group">
<div class="images">
</div>
<div class="details">
</div>
</div>
</div>
it's something like this:
newest image | some details here
newer image | some datails here
new image | some details here
old image | some details here
EDIT 1
I combined Lauri Elias' and iamde_coder's answer. I come up with this code which works almost similar to what is wanted. the only problem is that it displays the item (image&details in a div) 4 times. How can I eliminate the three? thanks!
$image_query = mysql_query ("SELECT filename, story FROM tbl_contest ORDER BY time DESC");
while($image_data = mysql_fetch_array($image_query)){
$imageName = stripslashes(mysql_real_escape_string($image_data['filename']));
$imageDetails = stripslashes(mysql_real_escape_string($image_data['story']));
$count = 0;
foreach($image_data as $imageName) {
echo '<div class="group">';
echo '<div class="images"><img src="/Mainfolder/image_entry/'.$imageName.'"></img></div>';
echo '<div class="details">'.$imageDetails.'</div></div>';
$count ++;
}
}
Now that you've given a little more code to help try using this:
$count = 0;
$image_query = mysql_query ("SELECT filename, story FROM tbl_contest ORDER BY time DESC") or die(mysql_error());
while($image_data = mysql_fetch_array($image_query)){
$imageName = stripslashes(mysql_real_escape_string($image_data['filename']));
$imageDetails = stripslashes(mysql_real_escape_string($image_data['story']));
$count++;
echo '<div class="group">';
echo '<div class="images"><img src="/Mainfolder/image_entry/'.$imageName.'" alt="Image '.$count.'" /></div>';
echo '<div class="details">'.$imageDetails.'</div></div>';
}
You could, for example, use a MySQL select somewhat like this:
SELECT name, description FROM my_database.images ORDER BY created_at DESC;
Then bind the result set to a variable in PHP like $images and then iterate on it and generate HTML like this:
foreach($images as $image) {
echo '<div class="group">';
echo '<div class="images"><img src="/images_folder/'.$image['name'].'"></img></div>';
echo '<div class="details">'.$image['description'].'</div></div>';
}
Related
This image shows that I assigned different house_ID's for each image. Despite that, I would like to display images that have the same house_id, instead of just displaying all of them. For example, I would like to only display images with the house_id of 4. Does anyone know how to do this?
This is my current code which just displays all of them in a slide show.
<?php
// Include the database configuration file
include_once 'dbConfig.php';
// Get images from the database
$query = $db->query("SELECT * FROM images2 ORDER BY house_id DESC");
?>
<div class="frame">
<div class="slideshow-container">
<?php if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
$imageURL = 'uploads2/'.$row["file_name"];?>
<div class="mySlides fade">
<img style="height: 200px;" src="<?php echo $imageURL; ?>">
</div><?php }?>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div></div>
I have a php function to retrieve the three most recent entries to a table that holds news highlights. Here is my function:
function getHighlights(){
return $this->query("
SELECT *
FROM `highlights`
ORDER BY `inserted` DESC
LIMIT 3
");
}
These highlights are then placed on my homepage via a foreach loop. Here is my code:
<?php foreach($highlights as $a){ ?>
<div class="col-md-6 highlight">
<div class="highlightItem">
<img class="highlight-backdrop" src="<?=$a->backdrop;?>">
<p class="highlight-title"><?=$a->title;?></p>
</div>
</div>
<?php } ?>
I'd like for my homepage to ALWAYS be in this format:
News Highlight Format. However, the only reason it's in that format right now is because the images have predefined sizes that fit nicely together.
I want to be able to reference the most recent news highlight and set that image to always display as 300 x 210. I also want to reference the next two highlights and set them to always display as 300 x 100.
What's the best course of action for this?
<?php foreach($highlights as $index => $a){ ?>
if($index == 0){
<div class="col-md-6 highlight">
<div class="highlightItem">
<img width="300" height="210" class="highlight-backdrop" src="<?=$a->backdrop;?>">
<p class="highlight-title"><?=$a->title;?></p>
</div>
</div>
}else{
<div class="col-md-6 highlight">
<div class="highlightItem">
<img width="300" height="100" class="highlight-backdrop" src="<?=$a->backdrop;?>">
<p class="highlight-title"><?=$a->title;?></p>
</div>
</div>
}
<?php } ?>
try to use that code
I have a profile that shows profiles in a list. as shown in the image below.
users table
id | email | full_name | job_title | bio | profile_photo
images table
image_id | id | artist_img
CODE
<?php
$db = dbconnect();
$stmt = $db->prepare('SELECT
users.email,
users.full_name,
users.job_title,
users.bio,
users.profile_photo,
images.id,
images.artist_img
FROM users
INNER JOIN images ON users.id=images.id GROUP BY images.id');
$stmt->execute();
$result = $stmt->get_result();
while (($row = mysqli_fetch_assoc($result)) != false) {
$id = $row['id'];
$full_name = $row['full_name'];
$email = $row['email'];
$job_title = $row['job_title'];
$bio = $row['bio'];
$ProfilePhoto = $row['profile_photo'];
$artist_img = $row['artist_img'];
if (isset($ProfilePhoto) && ! empty($ProfilePhoto)) {
$image = "$ProfilePhoto";
} else {
$image = "avatar.jpg";
}
echo "<div class='container team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='artist/$image'>
</div>
<div class=\"col-md-6\">
<strong>$full_name<br>$job_title</strong>
<br>
<p>$bio</p>
<a href='mailto:$email' class='btn btn-info'>Contact Me</a>
</div>
</div>
</div>
<div class=\"container space team-wrap\">
<div class=\"row\">
<div class=\"col-lg-12\">
<div id=\"gallery-slider\" class=\"slider responsive\">
<div>";
echo"
<img src=\"gallery/$artist_img\" alt=\"\"></a>";
echo "</div>
</div>
<hr>
</div>
</div>
</div>";
}
?>
Problem area
echo"<img src=\"gallery/$artist_img\" alt=\"\"></a>";
The issue I am having is that it repeats the profile for each image if the user has 5 images it will add 5 profiles 1 for each img.
and does not show the other users profile at all. show how it shows up is look at the image for example its got 4 images under profile 1 and it shows there profile pic.. well it repats all that info for each image I want the pics that have the same id as the user to show up as a slider like below..
and it also refuses to show the other profiles of other users.
yes because it is not seeing the variable because you echo it as text
echo"<img src=\"gallery/$artist_img\" alt=\"\"></a>";
should be
$r=0;
foreach ($images as $image.id){
[$artist_img=$images[$r];
echo "<img src=\"gallery/".$artist_img."\" alt=\"\"></a>";
$r++;
}
//
i don't like to echo to much html because very easy to make a mistake that way i prefer it is to stay in html and just echo my variable like the but that is just me
<html>
<body>
<a><img src="gallery/<? php echo $artist_img; ?>" alt=""></a>
</body>
</html>
do you see here you fetch the variable for the picture as single row
$artist_img = $row['artist_img'];
you need to make it a array because it is a array you must remember using inner generates a number of pieces of data, maybe for you it will be better to run 2 query second query loads the images.inner join is useful for some people but complex and dont really give any advantage because still searches the whole tables twice to get the results
something like this might work for for you
$artist_img2=array();
//because there are more then one piece of data in it
$artist_img2 = $row['images'];
//then you need to do another loop to put the data in variables or echo them out
// in the loop
//note the row refers to id and not image.id because in the inner array the key will be id
$artist_img3=row2['id'];
echo "<img src=\"gallery/".$artist_img3."\" alt=\"\"></a>";
//end loop
I have this php array. Where in my database i have a field called body, and in that field there is some html code. Like this:
<h1>title</h1><img src="http://farm5.staticflickr.com/4075/4788694752_d03557765b_z.jpg" alt=""/>
Here is my php code:
<?php
$q = "SELECT * FROM journals ORDER BY timestamp DESC";
$r = mysqli_query($dbc, $q);
while($journal_list = mysqli_fetch_assoc($r)) { ?>
<div class="col-md-4">
<a class="list-group-item" href="journal.php?id=<?php echo $journal_list['id']; ? >">
<h4 class="list-group-item-heading"><?php echo $journal_list['body']; ´?></h4>
</a>
</div>
<?php } ?>
In the h4 im calling the body field in the database. But i only want the img in that field??
Try phpquery:
$src = phpQuery::newDocumentHTML($journal_list['body'])->find('img')->attr('src');
This is a little hack that you can use
$img = explode('img',$journal['body']);
$final_img = '<img '.$img[1];
Now echo image as
<h4 class="list-group-item-heading"><?php echo $final_img; ?></h4>
I have a dynamically generated DIV
<div class="content drag-desired">
<?php
$result = mysql_query("SELECT * FROM XXXX WHERE qty != 0");
while($row=mysql_fetch_assoc($result))
{
echo '<div class="product"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" />
<div>'.$row['price'].'$</div></div>';
}
?>
<div class="clear"></div>
</div>
the while loop makes the list be very long,
Any idea how to make the div contains 6 items only and show the fetched items 6 by 6?
I don't know the logic behind the scene. :)
I will be appreciated, if someone explain the follow chart for making the div slides.
Thanks
Like so:
<div class="content drag-desired">
<?php
$result = mysql_query("SELECT * FROM XXXX WHERE qty != 0");
$counter = 0;
while($row=mysql_fetch_assoc($result))
{
if($counter==0)
echo '<div class="slide">';
echo '<div class="product"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" />
<div>'.$row['price'].'$</div></div>';
if($counter==5)
echo '<div>';
$counter++;
if($counter > 5)
$counter = 0;
}
?>
<div class="clear"></div>
</div>
So, the code below counts to 6 and wraps 6 items inside "slide". I think you understand the logic I used :) And with a little hint of CSS/JavaScript you can make your own slider that changes slide to be shown.