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; ?>
Related
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 want to display first image,title and description in col1 div, second in col3 and so on
but in this first image repeat in all div . how to solve this
<?php
include('connection.php');
$perPage=1;
$i=1;
if(isset($_REQUEST['act']) && trim($_REQUEST['act']=='load_data')){
$page=1;
if(!empty($_GET["page"])) {
$page = $_GET["page"];
}
$start = ($page-1)*$perPage;
if($start < 0) $start = 0;
$msg='';
$q="SELECT * FROM addimages order by id desc limit $start,$perPage ";
$res = mysql_query($q);
$row = mysql_fetch_array($res);
$id = $row['art_id'];
$qe="select banner from images where id=$id";
$rs=mysql_query($qe);
$name=mysql_fetch_array($rs);
//$id=$row['id'];
//$no=mysql_num_rows($res);
if(!$row==""){
$msg .= "<div class='article_index' id='".$row["art_id"]."'><div class='article banner_add'><a href='#'><img height='220' src='./uploads/" . $name['banner'] . "' /></a></div>";
$msg .=" <div class='post_main' >
<div class='col1'>
<div class='post_img'><a href='#'><img class='lazy' data-original='./uploads/" . $row['image'] . "' width='633' height='441' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
</div>
<div class='post_contant_main'>
<div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
<div class='post_contant'>".$row['desc']."</div>
</div>
</div>";
$msg .=" <div class='col3'>
<div class='post_img'><a href='#'><img class='lazy' width='299' height='191' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
</div>
<div class='post_contant_main'>
<div class='post_title post_rtitle'><h2><a href='#'>".$row['title']."</a></h2></div>
</div>
</div>
<div class='col3'>
<div class='post_img'><a href='#'><img class='lazy' width='299' height='191' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
</div>
<div class='post_contant_main'>
<div class='post_title post_rtitle'><h2><a href='#'>".$row['title']."</a></h2></div>
</div>
</div>
<div class='col2'>
<div class='post_img'><a href='#'><img class='lazy' width='461' height='300' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
</div>
<div class='post_contant_main'>
<div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
<div class='post_contant'>".$row['desc']."</div>
</div>
</div>
<div class='col2'>
<div class='post_img'><a href='#'><img class='lazy' width='461' height='300' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
</div>
<div class='post_contant_main'>
<div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
<div class='post_contant'>".$row['desc']."</div>
</div>
</div>
</div>
</div>
";
}
$msg .="<a class='next' href='#'></a>
<input type='hidden' id='pageno' name='pageno' value=''>";
echo $msg;
}
?>
i want to increase row array to next id and display its content
i am using infinite scroll plugin
you fetch only one top row. If you want to get all rows, you need to loop it thought.
while ($row = $result->fetch_row()) {
$msg .=" <div class='post_main' >
<div class='col1'>
<div class='post_img'><a href='#'><img class='lazy' data-original='./uploads/" . $row['image'] . "' width='633' height='441' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
</div>
<div class='post_contant_main'>
<div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
<div class='post_contant'>".$row['desc']."</div>
</div>
</div>";
}
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.
I tried to connect the page with phpmyadmin in local server using PDO but i couldnt connect to it and i'm getting SQLSTATE error can anyone please help me through it.
config.php:
<?Php
$dbhost_name = "localhost";
$database = "seekouttech";// database name
$username = "root"; // user name
$password = ""; // password
//////// Do not Edit below /////////
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
pagination1.php
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<?php include "./includes/menu_include.php";
$t=$_GET['id2'];
echo $t;
$nws_id = $t;
?>
<?Php
include "config.php"; // All database details will be included here
$page_name="pagination1.php";
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}
$eu = ($start - 0);
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
$query2=" SELECT * FROM comment where newsid='$t' ";
$count=$dbo->prepare($query2);
$count->execute();
$nume=$count->rowCount();
$query=" SELECT * FROM comment limit $eu, $limit ";
foreach ($dbo->query($query) as $row) {
echo $row[name];
}
if($nume > $limit ){
if($back >=0) {
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>";
}
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
$l=$l+1;
}
if($this1 < $nume) {
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
?>
<div class="main-content-top">
<div class="main-wrapper">
<div class="row">
<div class="large-6 columns">
<h2>Blog</h2>
</div>
<div class="large-6 columns">
<ul class="breadcrumbs right" style="font- size:18px;">
<li style="text-transform:none;">You are here: </li>
<li>HOME</li>
<li><span>BLOG</span></li>
<li><span>BLOG DETAILS</span></li>
</ul>
</div>
</div>
</div>
</div>
<div class="main-wrapper">
<div class="content_wrapper">
<div class="row">
<div class="large-8 columns">
<article class="post single-post">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result_comment=mysql_query("select newsid from comment where newsid='$t' ");
$count = mysql_num_rows($result_comment);
$result = mysql_query("SELECT * FROM news where newsid='$t'");
while($row = mysql_fetch_array($result))
{
?>
<div class="post_img">
<img class="post_image" src="display_image.php?
pic_id=<?php echo $row['id']; ?>" alt="post title">
<ul class="meta">
<li><i class="icon-comment"></i><?php echo $count." comments";?></li>
<li><i class="icon-calendar"></i><?php echo $row['date']; ?></li>
</ul>
</div>
<h3><?php echo $row['heading']?></h3>
<p class="post_text" style="text-align:justify;"><?php echo $row['description']?></p>
</article>
<div class="comments">
<h4 class="color comment_count"><?php echo $count." comments";?></h4>
<div class="com_meta">
<span class="user_name"><br>
<?php
$result_comment1=
mysql_query("select * from comment where newsid='$t' ORDER BY id DESC ");
while($row9 = mysql_fetch_array($result_comment1))
{
echo "<b>".$row9['name']."</b>";
?><span class="com_date"><?php echo $row9['date'];?></span><br>
<p class="com_text"><?php echo $row9['comment'];?>
</p>
<?php }
?>
</div>
<div class="com_content">
</div>
</div>
</div>
<?php
}mysql_close();
?>
<aside class="large-4 columns">
<div class="widgets">
<div class="section-container tabs" data-section="tabs">
<section class="section">
<p class="title"><i class="icon-random"></i> </p>
<div class="content">
<marquee direction="up" scrollamount="1">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result2=mysql_query("SELECT * FROM news ORDER BY id ASC limit 4");
while($row2 = mysql_fetch_array($result2))
{
$id3=$row2['newsid'];
?>
<p style="margin-top:-6px;"><a href="blog-details.php?id2=<?php echo $id3;?>">
<?php
$desc2=$row2['heading'];
echo SUBSTR($desc2,0,40);
echo "....";
?> </a>
</p>
<?php
}mysql_close();
?>
</marquee>
</div>
</section>
<section class="section">
<p class="title"><i class="icon-comment-alt"></i></p>
<div class="content">
<ul class="categories">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result_comment=mysql_query("select * from comment where newsid='$t' ");
//echo $t;
while($row9 = mysql_fetch_array($result_comment))
{
echo '<br>'.$row9['comment'];?> ----<h7 style="color:#000000; font:bold">
<?php
echo $row9['name'];
?>
</h7>
<?php
}
mysql_close();
?>
</ul>
</div>
</section>
</div>
</div>
<div class="widgets" style="clear:both;">
<h3>Tags</h3>
<ul id="tags">
<li>App Development</li>
<li>Web Design</li>
<li>User Interface</li>
<li>Branding</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="widgets">
<h3>Services</h3>
<ul id="example1" class="accordion">
<li>
<div class="handle"><span><i></i>
</span>Logo Design </div>
</li>
<li>
<ul class="panel loading">
<li>How about…</li>
<li>… a list …</li>
<li>… of items?</li>
</ul>
</li>
<li>
<p class="panel loading">An image in a paragraph.</p>
</li>
<li><div class="handle"><span><i></i>
</span>On-line Marketing</div>
</li>
<div class="widgets">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result5=mysql_query("SELECT * FROM quoteday ORDER BY id DESC limit 1");
while($row5 = mysql_fetch_array($result5))
{
?>
<h3>Quote of the Day</h3>
<div class="panel">
<p>
<?php echo'"';
echo $row5['quoteoftheday'];
echo '"';
?>
</p>
</div>
<?php
}
mysql_close();
?>
</div>
</aside>
</div>
</div>
</div>
<?php include "./includes/footer_section.php";?>
This is the code where i want to implement pagination and i want to retrieve all the comments that i fetched from db using mysql.
The obvious answer is that mysql is not running.
Please try connecting to mysql on the command line to confirm it is running
A newbie here. Trying to increment CSS ID selector with PHP.
Following the code I have
<?php
$thumbnails = get_post_meta($post->ID, "plans", false);
if ($thumbnails[0] != '') :?>
<div id="images-box">
<?php foreach($thumbnails as $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
} ?>
</div>
<?php endif; ?>
What I want is
<div id="image-1" class="image-lightbox">
<div id="image-2" class="image-lightbox">
<div id="image-3" class="image-lightbox">
I tried with many options that were answered here (http://codepad.org/OHuTxQPI) but couldn't get it right.
Simply add $id=1; and $id++; in your code.
<?php
$id = 1;
foreach($thumbnails as $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
$id++;
} ?>
Edited: $id=1; should be used if you want to start from id='image-1'.
You're using $id as a counter but don't actually define or increment anywehre.
<?php
$thumbnails = get_post_meta($post->ID, "plans", false);
if ($thumbnails[0] != '') :?>
<div id="images-box">
<?php
$id = 0;
foreach($thumbnails as $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
$id++;
} ?>
</div>
<?php endif; ?>
Unlike the rest, I'm using a straight for() loop instead of foreach() to give more control (ok it's really just cuz I'm OCD and like to use $i).
Here's the demo
PHP:
<?php
$thumbnails = array(0 => array('thumb' => 'image.jpg'), 1 => array('thumb' => 'image2.jpg'));
// $thumbnails = get_post_meta($post->ID, "plans", false);
if (isset($thumbnails)): ?>
<div id="images-box">
<?php
$i = 0;
$thumbs = count($thumbnails);
for($i;$i < $thumbs;$i++) { ?>
<div class="holder">
<div id="image-<?php print $i; ?>" class="image-lightbox">
<span class="close">X</span>
<img src="<?php print $thumbnails[$i]['thumb']; ?>" alt="" />
<a class="expand" href="#image-<?php print $i; ?>"></a>
</div>
<?php }; ?>
</div>
<?php endif; ?>
HTML output:
<div id="images-box">
<div class="holder">
<div id="image-0" class="image-lightbox">
<span class="close">X</span>
<img src="image.jpg" alt="" />
<a class="expand" href="#image-0"></a>
</div>
<div class="holder">
<div id="image-1" class="image-lightbox">
<span class="close">X</span>
<img src="image2.jpg" alt="" />
<a class="expand" href="#image-1"></a>
</div>
</div>
Use Counter for $id as told by John or use $id as index for foreach loop as below.
<?php
$thumbnails = get_post_meta($post->ID, "plans", false);
if ($thumbnails[0] != '') :?>
<div id="images-box">
<?php foreach($thumbnails as $id=> $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
} ?>
</div>
<?php endif; ?>