|
|
|
Gallery โดยดึงข้อมูลมาจาก ฐานข้อมูล แล้งแสดงเป็น slide |
|
|
|
|
|
|
|
ถ้าเราจะให้โชว์เฉพาะรูปภาพที่มี id ตรงกัน จะต้อง เขียนโค้ดประมาณใหนเหรอครับ โดยดึงข้อมูลมาจาก mysql ครับ
โค้ดประมาณนี้ครับ
Code (PHP)
<div class="row">
<div class="col-md-9">
<div class="activitiesIntro">
<div class="activitiesNavItems">
<?php
$id = isset($_GET['id']) ? (int) $_GET['id'] : 1;
$re =array();
$str="SELECT * FROM title_gallery";
$result=mysqli_query($conn,$str);
while ($p=mysqli_fetch_assoc($result)){
$re[]=$p['tg_id'];
?>
<div class="activitiesNavItem">
<a href="?id=<?php echo $p['tg_id']?>" class="<?php if ($p['tg_id'] == $id){echo "active";} ?>"><?php echo $p['tg_title'];?></a>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
<div class="galleryContent">
<div class="galleryHeader">
<h1><?php
$str1 = "SELECT * FROM title_gallery WHERE tg_id = $id";
$result1 = mysqli_query($conn, $str1);
$p1 = mysqli_fetch_assoc($result1);
echo $p1['tg_title'];
?></h1>
</div>
<div class="galleryItems" id="<?=$p1['tg_id']?>">
<div class="row">
<?php
$tt = $p1['tg_id'];
$str1 = "SELECT * FROM title_gallery WHERE tg_id = $tt";
$result1 = mysqli_query($conn, $str1);
$p2 = mysqli_fetch_assoc($result1);
$gallery = array();
$strsql = "SELECT * FROM gallery WHERE tg_id = $tt ORDER BY tg_id ASC";
$mee = mysqli_query($conn, $strsql);
while ($ee = mysqli_fetch_assoc($mee)) {
$gallery[]=$ee;
?>
<div class="col-sm-3 col-xs-6">
<div class="galleryItem" data-toggle="modal" data-target="#galleryModal<?php echo $ee['g_id']; ?>">
<figure class="images">
<img src="<?php echo resize_crop_image(400, 400, 'images/gallery/' . $ee['img'], 'images/gallery1/' . $ee['img']); ?>">
</figure>
<br>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<?php
foreach ($gallery as $ww) {
?>
<div data-interval="500" data-pause="hover" class="modal fade modalTheme modalGallery carousel slide"
id="galleryModal<?=$ww['g_id']?>" tabindex="-1" role="dialog"
aria-labelledby="galleryModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<button type="button" class="btnCloseModal" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">X</span></button>
<div class="modal-body">
<div class="modalGalleryDisplay carousel-inner">
<?php
$rst = "SELECT title_gallery.tg_id,title_gallery.tg_title,gallery.g_id,gallery.img,gallery.tg_id FROM title_gallery,gallery WHERE title_gallery.tg_id=gallery.tg_id ORDER BY '".$ww['g_id']."'";
$obb = mysqli_query($conn, $rst);
$i = 0;
while ($wp = mysqli_fetch_assoc($obb)) {
?>
<p class="image item <?= ($i++ == 0 ? 'active' : '') ?>" align="center"><img
src="images/gallery1/<?php echo $wp['img'] ?>"></p>
<?php
}
?>
<div class="modalGalleryControls">
<div class="controlLeft carousel-control left" href="#galleryModal<?=$ww['g_id']?>" data-slide="prev"></div>
<div class="controlRight carousel-control right" href="#galleryModal<?=$ww['g_id']?>" data-slide="next"></div>
</div>
</div>
<div class="modalTitleText"><?php echo $wp['tg_title']; ?></div>
</div>
</div>
</div>
</div>
<?php
}
?>
Tag : PHP, MySQL, HTML/CSS, jQuery
|
|
|
|
|
|
Date :
2016-08-08 22:23:13 |
By :
pharit |
View :
1341 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อธิบายไม่ชัดเจนครับ ว่า id ใน table ไหนครับ ก็เพียงแค่ where ให้ถูกต้องครับ
|
|
|
|
|
Date :
2016-08-10 09:20:15 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|