i am writing a php script that retrieves images from a database and shows them on page inside an album , each album contains several images...
here is an example for the code below :
$sql = "SELECT * FROM tbl_album where status='process' ORDER BY albumid DESC LIMIT $start_from, 12";
<?php
$rs_result = mysql_query ($sql,$con);
while ($row = mysql_fetch_assoc($rs_result))
{
$aid=$row['albumid'];
$aimage=$row['image'];
$aname=$row['name'];
$astatus=$row['status'];
echo '<div class="col-lg-4 col-md-6 col-sm-6 agile_gallery_grid">';
echo '<div class="hover ehover14">';
?>
<?php
echo"<a href='#details?d=$aid' onclick='showfunction()'>";
echo "<img src='admin/acatch/$aimage' class='img-responsive' alt='$aname' width='200' height='200' data-picture_id='$aid'>";
echo'</a>';
}
?>
this code shows all the albums contained in the database ,
but what i want to do is that when i click on the album cover , i want to display the images inside it on the same page , but i am not able to pass the album id to another php script on the same page to do this,
please if anyone can help
thank u in advance
Have a look at the following code:
<?php
$sql = "SELECT * FROM tbl_album where status='process' ORDER BY albumid DESC LIMIT $start_from, 12";
$rs_result = mysql_query($sql, $con);
while($row = mysql_fetch_assoc($rs_result)):
$aid=$row['albumid'];
$aimage=$row['image'];
$aname=$row['name'];
$astatus=$row['status'];
?>
<div class="col-lg-4 col-md-6 col-sm-6 agile_gallery_grid">
<div class="hover ehover14">
<a href='#details?d=$aid' onclick='showfunction()'>
<img src="admin/acatch/<?=$aimage?>" class="img-responsive" alt="<?=$aname?>" width="200" height="200" data-picture_id="<?=$aid?>">
</a>
</div>
</div>
<div class="gallery_album" id="gallery_album_<?=$row['albumid']?>">
<?php
/**
* now collect all images associated with each album by using $aid
*/
$sql_images = "SELECT * FROM tbl_album_images WHERE fk_album_id = $aid";
$images_result = mysql_query($sql_images, $con);
while($image = mysql_fetch_assoc($images_result)):
?>
<div class="gallery_album_image"><img src="<?=$image['dir_and_filename']?>"></div>
<?php
endwhile;
?>
</div>
<?php endwhile; ?>
What we are doing here is gettign all the albums as you allready does. But we introduce a subquery inside the first while-loop to fetch all associated images for each album.
We put these images inside new div-container with a unique album id you can use to show or hide the actual album with your showfunction()
Use CSS and javascript to show or hide accordingly.
OBS! WARNING!! Your mysql queries, and the one I provided, is very very BAD!
Have a look into prepared statement using php PDO or mysqli...
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>
Hello please someone can help me with this code? I think there i can remove * and GET id.
<div class="col-md-4">
<h1>Sidebar</h1>
<?php
require_once 'connessione.php';
$id=$_GET['id'];
$query = "SELECT * FROM campi_name where id='$id'";
$stmt = $DBcon->prepare( $query );
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
?>
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="..." alt="...">
</a>
</div>
</div>
<?php
}
?>
</div>
How can i show only item (from db) related to the Brand row from table campi_name?
and with code like that how i can show 5 random item from campi_name?
Thank you!
For the first question you can use
$query = "SELECT Brand FROM campi_name WHERE id='" . $id . "'";
I'm not sure because I haven't understand what you are asking. Do you want to select only Brand column or what? Do you want to select just the row that content some letters?
For the second question use
$query = "SELECT * FROM campi_name ORDER BY rand() LIMIT 5"
I have database name is "db" Table is 'tbl_pro' is Feild are "msid" "subid" "pid" and "pname".
when I try to fetch the data through "msid" from URL it is working fine on a new page. but through "pname" I am not able to get it. here is my code
Page 1 code:
<?
$QryP=mysql_query("Select * from tbl_pro where Pname='test' order by Rank desc") or die("Error loading Products");
if(mysql_num_rows($QryP)>0) {
while($rs=mysql_fetch_array($QryP)){
?>
<div class="col-md-3 col-sm-4 ">
<div class="w-box product">
<figure>
<img alt="" src="upload/spic/<?=$rs["Spic"]?>" class="img-responsive img-center">
</figure>
<h2><?=$rs["Pname"]?></h2>
<p>
on the other page its.
Page 2 code:
<?
$QryP=mysql_query("Select * from tbl_pro where Pname=".$_REQUEST["Pname"]." AND Display='y'" ) or die("Error loading Products");
if(mysql_num_rows($QryP)>0) {
while($rs=mysql_fetch_array($QryP)){
?>
if i use "msid" instead of "Pname" its working fine.
Its better to go with the like operator when you were using a string in a query
if(isset($_REQUEST['Pname'])){$Pname=$_REQUEST['Pname'];}else{$Pname='';}
if(Pname!=''){
$QryP=mysql_query("Select * from tbl_pro where Pname like '%".$Pname."%' AND Display='y'" ) or die("Error loading Products");
I am trying to list products images , and show their own gallery with popup fancybox. A can list all the images from database products but cant filter when clicking the image. It shows all photos.
Can you help me please.
Regards
<?php $query_product = mysql_query("SELECT * FROM products WHERE status = '1' AND language_parent_id = '0' AND id = '".$row_product_id['product_id']."' ORDER BY sort_order");
$row_product = mysql_fetch_array($query_product);
$imageFile = HTTP_RESIM.'products/'.$row_product['image'];
?>
<section class="flexslider">
<ul class="slides">
<?php $imageFile = HTTP_RESIM.'products/'.$row_product['image'];
$query_resim = mysql_query("SELECT * FROM product_image WHERE product_id = '".$row_product['id']."' AND status = '1' ORDER BY sort_order");
while($row_product_resim = mysql_fetch_array($query_resim)){ ?>
<?php $imageFile2 = HTTP_RESIM.'product_image/'.$row_product_resim['image']; ?>
<li><?php echo "<a href=\"$imageFile2\" rel=\"fancybox-gallery\" ><img src=\"$imageFile\" /></a>"; ?> </li>
<?php } ?>
</ul>
</section>
Their docs say
you should use it like this.
<a class="fancybox" rel="group" href="big_image_1.jpg"><img src="small_image_1.jpg" alt="" /></a>
So you will need to add the class "fancybox" to the anchor tag.
Edit: You should not use the mysql functions, they are outdated and very unsafe.
Look into PDO (http://php.net/manual/en/book.pdo.php) or mysqli (http://php.net/manual/en/book.mysqli.php):
I have an issue with bootstrap and creating a 4 column responsive grid from a mysql response.
The problem is that if the second mysql query has a variable number of results, it brakes the grid.
Here is my code (where the first query has 9 results and the second query has a variable number of results):
<?php
$a = "SELECT * FROM $table_users ORDER BY username";
$result = mysql_query($a);
?>
<div class="container">
<div class="row">
<?php while ($row = mysql_fetch_array($result)) {?>
<div class="col-xs-3" style="background-color:aqua;">
<?php echo $row['username'];
$b = "SELECT * FROM $table_presents WHERE bought_for='$row[username]' OR bought_for='' ORDER BY id";
$result_presents = mysql_query($b) or die(mysql_error());
while ($row_presents = mysql_fetch_array($result_presents)) {
?>
<div style="background-color:red;">
Hello world!
</div>
<?php }?>
</div>
<?php }?>
</div>
</div>
which gives me this:
enter image description here
instead of this (obviously with many 'Hello world'):
enter image description here
Any help greatly appreciated!
Bootstrap doesn't claim to do any kind of elegant bin-packing on panels with different sizes. You could do some programming or css work to make all your panels the same size.
If that doesn't work for your application, you're going to need a layout library that does bin-packing so these panels of different sizes align properly.
There are a few such libraries available as jQuery plugins.
In this, $row[username] is wrong as it should be $row['username'].
$b = "SELECT * FROM $table_presents WHERE bought_for='$row[username]' OR bought_for='' ORDER BY id";
BTW, I changed your code bit. Please Try this.
<?php
$a = "SELECT * FROM $table_users ORDER BY username";
$result = mysql_query($a);
?>
<div class="container">
<div class="row">
<?php while ($row = mysql_fetch_array($result))
{
$username=$row['username'];
?>
<div class="col-xs-3" style="background-color:aqua;">
<?php echo $username;
$b = "SELECT * FROM $table_presents WHERE bought_for='$username' OR bought_for='' ORDER BY id";
$result_presents = mysql_query($b) or die(mysql_error());
while ($row_presents = mysql_fetch_array($result_presents)) {
?>
<div style="background-color:red;">
Hello world!
</div>
<?php }?>
</div>
<?php }?>
</div>
</div>
[NOTE: Users can inject your SQL commands. Use prepared statements and parameterized queries. For more info, click Prevent SQL Injections