I am using jQuery UI tabs to make a dynamic tabs using php and mysql.
My php code below get the data from the mysql database and display it out.
Normally the html code will look like:
<div id="featured" >
<ul class="ui-tabs-nav">
<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1"><img src="images/image1-small.jpg" alt="" /><span>15+ Excellent High Speed Photographs</span></li>
<li class="ui-tabs-nav-item" id="nav-fragment-2"><img src="images/image2-small.jpg" alt="" /><span>20 Beautiful Long Exposure Photographs</span></li>
<li class="ui-tabs-nav-item" id="nav-fragment-3"><img src="images/image3-small.jpg" alt="" /><span>35 Amazing Logo Designs</span></li>
<li class="ui-tabs-nav-item" id="nav-fragment-4"><img src="images/image4-small.jpg" alt="" /><span>Create a Vintage Photograph in Photoshop</span></li>
</ul>
<!-- First Content -->
<div id="fragment-1" class="ui-tabs-panel" style="">
<img src="images/image1.jpg" alt="" />
<div class="info" >
<h2><a href="#" >15+ Excellent High Speed Photographs</a></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>
</div>
</div>
<!-- Second Content -->
<div id="fragment-2" class="ui-tabs-panel ui-tabs-hide" style="">
<img src="images/image2.jpg" alt="" />
<div class="info" >
<h2><a href="#" >20 Beautiful Long Exposure Photographs</a></h2>
<p>Vestibulum leo quam, accumsan nec porttitor a, euismod ac tortor. Sed ipsum lorem, sagittis non egestas id, suscipit....<a href="#" >read more</a></p>
</div>
</div>
<!-- Third Content -->
<div id="fragment-3" class="ui-tabs-panel ui-tabs-hide" style="">
<img src="images/image3.jpg" alt="" />
<div class="info" >
<h2><a href="#" >35 Amazing Logo Designs</a></h2>
<p>liquam erat volutpat. Proin id volutpat nisi. Nulla facilisi. Curabitur facilisis sollicitudin ornare....<a href="#" >read more</a></p>
</div>
</div>
<!-- Fourth Content -->
<div id="fragment-4" class="ui-tabs-panel ui-tabs-hide" style="">
<img src="images/image4.jpg" alt="" />
<div class="info" >
<h2><a href="#" >Create a Vintage Photograph in Photoshop</a></h2>
<p>Quisque sed orci ut lacus viverra interdum ornare sed est. Donec porta, erat eu pretium luctus, leo augue sodales....<a href="#" >read more</a></p>
</div>
</div>
</div>
And i am using php to dynamically echo out the html :
<div id="featured" >
<ul class="ui-tabs-nav">
<?php
$count = 0; // Initialize counter
$rows = array();
while($row = mysql_fetch_array( $query )) {
$rows[] = $row;
$count = ++$count;
echo "<li class='ui-tabs-nav-item ui-tabs-selected' id='nav-fragment-" . $count . "'><a href='#fragment-" . $count . "'><img class='thumb' src='$row[imagelink]' alt='' /><span>$row[title]</span></a></li>\n";
}
?>
</ul>
<?php
$count2 = 0; // Initialize counter
$rows2 = array();
while($row2 = mysql_fetch_array( $query )) {
$rows2[] = $row2;
$count2 = ++$count2;
echo "<div id='fragment-" . $count2 . "' class='ui-tabs-panel' style=''>\n";
echo "<img src='$row[imagelink]' alt='' />\n";
echo "<div class='info' ><h2><a href='$row[link]'>$row[title]</a></h2><p>$row[description]</p></div>\n";
}
?>
</div>
However, it only generates the li(tabs) and not the fragments(the content).
What's my problem here?
Your problem is that your $query (MySQL result object) reaches the end of the result rows, and then your second loop will not start over from the beginning.
This should solve the problem: http://www.krio.me/loop-twice-through-a-php-mysql-result-set/
However, I would suggest something closer to creating your own temporary PHP variable to store all the data in and use that to loop over it the first and second time. Just a suggestion.
I do not know the performance of the data seek method described in the website linked above.
EDIT: You are already storing the data in the $rows variable. In your second loop, loop through the $rows variable instead of using the mysql_fetch_array function.
Code Added (did not test, but should give you a good idea):
<div id="featured" >
<ul class="ui-tabs-nav">
<?php
$count = 0; // Initialize counter
$rows = array();
while($row = mysql_fetch_array( $query )) {
$rows[] = $row;
$count = ++$count;
echo "<li class='ui-tabs-nav-item ui-tabs-selected' id='nav-fragment-" . $count . "'><a href='#fragment-" . $count . "'><img class='thumb' src='$row[imagelink]' alt='' /><span>$row[title]</span></a></li>\n";
}
?>
</ul>
<?php
$count2 = 0; // Initialize counter
$rows2 = array();
foreach($rows as $row2) {
$count2 = ++$count2;
echo "<div id='fragment-" . $count2 . "' class='ui-tabs-panel' style=''>\n";
echo "<img src='$row[imagelink]' alt='' />\n";
echo "<div class='info' ><h2><a href='$row[link]'>$row[title]</a></h2><p>$row[description]</p></div>\n";
}
?>
</div>
just change your
while($row2 = mysql_fetch_array( $query )) {
to
foreach($rows as $row2) {
However, here is a better version of your code
First, get your data into array. Do it near the place where you run your query. Keep all SQL operations in one place. And do not mix them with HTML operations!
$count = 0; // Initialize counter
$rows = array();
while($row = mysql_fetch_array( $query )) {
$rows[++$count] = $row;
}
Then move to HTML operations:
<div id="featured" >
<ul class="ui-tabs-nav">
<?php foreach($rows as $count => $row): ?>
<li class='ui-tabs-nav-item ui-tabs-selected' id='nav-fragment-<?=$count?>'>
<a href='#fragment-<?=$count?>'>
<img class='thumb' src='<?=$row['imagelink']?>' alt='' />
<span><?=$row['title']?></span>
</a>
</li>
<?php endforeach ?>
</ul>
<?php foreach($rows as $count => $row): ?>
<div id='fragment-<?=$count?>' class='ui-tabs-panel' style=''>
<img src='<?=$row[imagelink]?>' alt='' />
<div class='info' >
<h2><a href='<?=$row['link']?>'><?=$row['title']?></a></h2>
<p><?=$row['description']?></p>
</div>
</div>
<?php endforeach ?>
See how it become concise and at the same time keeps all HTML as is.
Related
I'm writing a PHP ecommerce website by referencing to other PHP ecommerce website (I used same image folder for both websites), however the image of last product is displayed in different size. Can somebody help with this? my website.
The code for my website is here:
<?php
$conn = $pdo->open();
try{
$stmt = $conn->prepare("SELECT * FROM products WHERE category_id = :catid");
$stmt->execute(['catid' => $catid]);
foreach ($stmt as $row) {
$image = (!empty($row['photo'])) ? 'images/'.$row['photo'] : 'images/noimage.jpg';
echo "
<li class='element no_full_width' data-alpha='Curabitur cursus dignis' data-price='20000'>
<ul class='row-container list-unstyled clearfix'>
<li class='row-left'>
<class='container_item'>
<img src='".$image."' class='img-responsive' alt='Curabitur cursus dignis'>
</a>
<div class='hbw'>
<span class='hoverBorderWrapper'></span>
</div>
</li>
<li class='row-right parent-fly animMix'>
<div class='product-content-left'>
<a class='title-5' href='product.php?product=".$row['slug']."'>".$row['name']."></a>
<span class='spr-badge' id='spr_badge_1293239619' data-rating='0.0'>
<span class='spr-starrating spr-badge-starrating'><i class='spr-icon spr-icon-star-empty' style=''></i><i class='spr-icon spr-icon-star-empty' style=''></i><i class='spr-icon spr-icon-star-empty' style=''></i><i class='spr-icon spr-icon-star-empty' style=''></i><i class='spr-icon spr-icon-star-empty' style=''></i></span>
<span class='spr-badge-caption'>
No reviews </span>
</span>
</div>
<div class='product-content-right'>
<div class='product-price'>
<span class='price'>
$".number_format($row['price'], 2)." </span>
</div>
</div>
<div class='list-mode-description'>
Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis amet voluptas assumenda est, omnis dolor repellendus quis nostrum. Temporibus autem quibusdam et aut officiis debitis aut rerum dolorem necessitatibus saepe eveniet ut et neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed...
</div>
<div class='hover-appear'>
<form action='#'' method='post'>
<div class='effect-ajax-cart'>
<input name='quantity' value='1' type='hidden'>
<button class='add-to-cart' type='submit' name='add'><i class='fa fa-shopping-cart'></i><span class='list-mode'>Add to Cart</span></button>
</div>
</form>
<div class='product-ajax-qs hidden-xs hidden-sm'>
<div data-href='./ajax/_product-qs.html' data-target='#quick-shop-modal' class='quick_shop' data-toggle='modal'>
<i class='fa fa-eye' title='Quick view'></i><span class='list-mode'>Quick View</span>
</div>
</div>
<a class='wish-list' href='./account.html' title='wish list'><i class='fa fa-heart'></i><span class='list-mode'>Add to Wishlist</span></a>
</div>
</li>
</ul>
</li>
";
}
}
catch(PDOException $e){
echo "There is some problem in connection: " . $e->getMessage();
}
$pdo->close();
?>
This is the website im referencing referenced website
And the code of the referenced website is here:
<?php
$conn = $pdo->open();
try{
$inc = 3;
$stmt = $conn->prepare("SELECT * FROM products WHERE category_id = :catid");
$stmt->execute(['catid' => $catid]);
foreach ($stmt as $row) {
$image = (!empty($row['photo'])) ? 'images/'.$row['photo'] : 'images/noimage.jpg';
$inc = ($inc == 3) ? 1 : $inc + 1;
if($inc == 1) echo "<div class='row'>";
echo "
<div class='col-sm-4'>
<div class='box box-solid'>
<div class='box-body prod-body'>
<img src='".$image."' width='100%' height='230px' class='thumbnail'>
<h5><a href='product.php?product=".$row['slug']."'>".$row['name']."</a></h5>
</div>
<div class='box-footer'>
<b>$ ".number_format($row['price'], 2)."</b>
</div>
</div>
</div>
";
if($inc == 3) echo "</div>";
}
if($inc == 1) echo "<div class='col-sm-4'></div><div class='col-sm-4'></div></div>";
if($inc == 2) echo "<div class='col-sm-4'></div></div>";
}
catch(PDOException $e){
echo "There is some problem in connection: " . $e->getMessage();
}
$pdo->close();
?>
im working on my crud skills, but im having some trouble. the first page shows a list of all blog posts, when the user clicks on read more it sends the specific posts id through the url and is recieved by the destination page which uses that id to display the single post/ heres the code for that part. it actually works fine
function display_single_post($title,$author,$date,$image,$content){
$main_page_blog_html = "<h2>
<a href='#'>%s</a>
</h2>
<p class='lead'>
by <a href='index.php'>%s</a>
</p>
<p><span class='glyphicon glyphicon-time'></span> Posted on %s</p>
<hr>
<img class='img-responsive' src='images/%s'>
<hr>
<p>%s</p>
<hr>
<hr>";
printf("{$main_page_blog_html}",$title,$author,$date,$image,$content);
if(isset($_GET["id"])){
$id = $_GET["id"];
$stmt = $connect->link->query("SELECT * FROM posts WHERE post_id = $id");
while($row = $stmt->fetch()){
$post_title = $row["post_title"];
$post_author = $row["post_author"];
$post_date = date('F j, Y \a\t g:ia', strtotime( $row["post_date"] ));
$post_image = $row["post_image"];
$post_content = $row["post_content"];
$id = $row["post_id"];
display_single_post($post_title,$post_author,$post_date,$post_image,$post_content);
}
}
like i said this all works fine. the get value is recieved and loads the post. the problem is when i try to use that $_get id in a query to insert a comment. all this code is on the one page im just showing the php without the html. anyway heres the code to insert the comment
if(isset($_POST["create_comment"])){
global $connect;
$post_id = $_GET["id"];
$comment_author = $_POST["comment_author"];
$author_email = $_POST["author_email"];
$comment_content = $_POST["comment_content"];
$comment_status = "pending";
edit with all the code
<div class="container">
<div class="row">
<!-- Blog Entries Column -->
<div class="col-md-8">
<h1 class="page-header">
Page Heading
<small>Secondary Text</small>
</h1>
<!-- First Blog Post -->
<?php
$connect = new db();
if(isset($_POST["create_comment"])){
global $connect;
echo "hello";
$post_id = $_GET["id"];
$comment_author = $_POST["comment_author"];
$author_email = $_POST["author_email"];
$comment_content = $_POST["comment_content"];
$comment_status = "pending";
$sql = "INSERT INTO comments(comment_post_id, comment_author, comment_email, comment_content, comment_status)
VALUES(:a,:b,:c,:d,:e)";
$stmt = $connect->link->prepare($sql);
$stmt->bindvalue(":a",$post_id);
$stmt->bindvalue(":b", $comment_author);
$stmt->bindvalue(":c",$author_email);
$stmt->bindvalue(":d",$comment_content);
$stmt->bindvalue(":e",$comment_status);
$stmt->execute();
}
function display_single_post($title,$author,$date,$image,$content){
$main_page_blog_html = "<h2>
<a href='#'>%s</a>
</h2>
<p class='lead'>
by <a href='index.php'>%s</a>
</p>
<p><span class='glyphicon glyphicon-time'></span> Posted on %s</p>
<hr>
<img class='img-responsive' src='images/%s'>
<hr>
<p>%s</p>
<hr>
<hr>";
printf("{$main_page_blog_html}",$title,$author,$date,$image,$content);
}
if(isset($_GET["id"])){
$id = $_GET["id"];
$stmt = $connect->link->query("SELECT * FROM posts WHERE post_id = $id");
while($row = $stmt->fetch()){
$post_title = $row["post_title"];
$post_author = $row["post_author"];
$post_date = date('F j, Y \a\t g:ia', strtotime( $row["post_date"] ));
$post_image = $row["post_image"];
$post_content = $row["post_content"];
$id = $row["post_id"];
display_single_post($post_title,$post_author,$post_date,$post_image,$post_content);
}
}
?>
<hr>
<!-- Blog Comments -->
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" method="post" action="post.php">
<div class="form-group">
<input type="text" class="form-control" name="comment_author" placeholder="name">
</div>
<div class="form-group">
<input type="email" class="form-control" name="author_email" placeholder="email">
</div>
<div class="form-group">
<textarea class="form-control" rows="3" name="comment_content"></textarea>
</div>
<button type="submit" name="create_comment" class="btn btn-primary">Submit</button>
</form>
</div>
<hr>
<!-- Posted Comments -->
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Start Bootstrap
<small>August 25, 2014 at 9:30 PM</small>
</h4>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
</div>
</div>
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Start Bootstrap
<small>August 25, 2014 at 9:30 PM</small>
</h4>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
<!-- Nested Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Nested Start Bootstrap
<small>August 25, 2014 at 9:30 PM</small>
</h4>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
</div>
</div>
<!-- End Nested Comment -->
</div>
</div>
</div>
Based on your code and your comments, I assume the page is called post.php and when you first reach the page it has the id on the url like this: post.php?id=156.
But once you submit the comments' form, since the action for said form it is simply post.php you're losing the id.
You could add the id on the action after post:
<form role="form" method="post" action="post.php?id=<?php echo $id; ?>">
or add a hidden input with the id:
<input type="hidden" name="id" value="<?php echo $id; ?>">
But then you'd have to reach it with $_POST
Another option is to use the SELF for the action like this:
<form role="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
This will retain the id but also any other get variables you may have on the url.
//EDIT
This is a simplification of the probelm which is working, if you visit post.php?id=456 (or any number) and then press Submit, you get the proper response:
<!-- First Blog Post -->
<?php
if(isset($_POST["create_comment"])){
$post_id = $_GET["id"];
echo "The id is: $post_id";
// gets comment and inserts into the db
}
if(isset($_GET["id"])){
$id = $_GET["id"];
// calls display_single_post
}
?>
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" method="post" action="post.php?id=<?php echo $id; ?>">
<button type="submit" name="create_comment" class="btn btn-primary">Submit</button>
</form>
</div>
I'm Stuck on below code... Accroding to my understanding below code should display all the rows data which has been created in my database... But im getting only 1 row data in result only one product on my product page... Please help...
<?php
include 'core/database/connect.php';
include 'core/includes/listhead.php';
$dynamiclist = "";
$sql = mysql_query("SELECT * FROM `index` ORDER BY price1 LIMIT 2");
$hotelcount = mysql_num_rows($sql);
if($hotelcount > 0) {
while($row = mysql_fetch_array($sql)) {
$id = $row['index_id'];
$pic = $row['main_pic'];
$country = $row['country1'];
$destination = $row['destination1'];
$price = $row["price1"];
$dynamiclist = '<div class=/"offset-2/">
<div class="col-md-4 offset-0">
<div class="listitem2">
<img src="'. $pic .'" alt=""/>
<div class="liover"></div>
<a class="fav-icon" href="#"></a>
<a class="book-icon" href="details.html"></a>
</div>
</div>
<div class="col-md-8 offset-0">
<div class="itemlabel3">
<div class="labelright">
<img src="images/filter-rating-5.png" width="60" alt=""/><br/><br/><br/>
<img src="images/user-rating-5.png" width="60" alt=""/><br/>
<span class="size11 grey">18 Reviews</span><br/><br/>
<span class="green size18"><b>'. $price .'</b></span><br/>
<span class="size11 grey">Avg/Night</span><br/><br/><br/>
<form action="http://demo.titanicthemes.com/travel/details.html">
<button class="bookbtn mt1" type="submit">Book</button>
</form>
</div>
<div class="labelleft2">
<b>'. $country .'</b><br/><br/><br/>
<p class="grey">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec semper lectus. Suspendisse placerat enim mauris, eget lobortis nisi egestas et.
Donec elementum metus et mi aliquam eleifend. Suspendisse volutpat egestas rhoncus.</p><br/>
<ul class="hotelpreferences">
<li class="icohp-internet"></li>
<li class="icohp-air"></li>
<li class="icohp-pool"></li>
<li class="icohp-childcare"></li>
<li class="icohp-fitness"></li>
<li class="icohp-breakfast"></li>
<li class="icohp-parking"></li>
<li class="icohp-pets"></li>
<li class="icohp-spa"></li>
</ul>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="offset-2"><hr class="featurette-divider3"></div>';
}
} else {
$dynamiclist = 'We Do Not Have Any Hotel Listed in This City';
}
?>
<?php echo $dynamiclist ?>
<?php include 'core/includes/listfooter.php'; ?>
You have two issues
Your database query is limited to 2 items (although that doesn't explain the 1 item problem you have at the moment)
removing LIMIT 2 will fix this
Secondly
$dynamiclist = '<div class=/"offset-2/">
the "=" sign means that you set it as the content each time.
This is fine except you echo it OUTSIDE your while loop
either echo it within your while loop or change it to
$dynamiclist .= '<div class=/"offset-2/">
notice the .= -> that Adds items to the end of the string.
Hope that helps
Change the
$dynamiclist = '<div class=/"offset-2/">
to
$dynamiclist .= '<div class=/"offset-2/">
If you want to load all rows, remove 'LIMIT' from your query.
i've this problem with WP_Query and the HTML output:
The Query:
<!-- Category posts -->
<!-- Entretencion -->
<article class="six column">
<?php
$caps = new WP_Query();
$caps->query('posts_per_page=4&category_name=entretencion');
while($caps->have_posts()) {
$caps->the_post();
$count++;
if($count == 1) {
?>
<!--First post -->
<h4 class="cat-title"><?php $category = get_the_category(); echo $category[0]->cat_name; ?></h4>
<div class="post-image">
<img src="<?php bloginfo( 'template_url' ); ?>/upload/imagepost1.jpg" alt="">
</div>
<div class="post-container">
<h2 class="post-title">Create a Flexible Folded Paper Effect Using CSS3 Features</h2>
<div class="post-content">
<p>Venenatis volutpat orci, ut sodales augue tempor nec. Integer tempus ullamcorper felis eget dipiscing. Maecenas orci justo, mollis at tempus ac, gravida non</p>
</div>
</div>
<div class="post-meta">
<span class="comments">24</span>
<span class="author">nextwpthemes</span>
<span class="date">13 Jan 2013</span>
</div>
<!-- End of first post -->
<?php } if($count >= 2) { //Contador ?>
<!-- Second and others posts -->
<div class="other-posts">
<ul class="no-bullet">
<!-- Repeat this list with post 2, 3, and 4 -->
<li id="<?php echo $post->ID; ?>">
<img src="<?php bloginfo( 'template_url' ); ?>/upload/thumb1.jpg" alt="">
<h3 class="post-title">Check Out the New Recommended Resources on Webdesigntuts+</h3>
<span class="date">13 Jan 2013</span>
</li>
</ul>
</div>
<?php } // Fin contador ?>
<?php } ?>
</article>
But the HTML output repeat 3 div with class other-post.
The problem (left) the original (right)
How to repeat only li tags?
<!-- Category posts -->
<!-- Entretencion -->
<article class="six column">
<?php
$count = '';
$perpage = 4;
$caps = new WP_Query();
$caps->query('posts_per_page='.$perpage.'&category_name=entretencion');
while($caps->have_posts()) {
$caps->the_post();
$count++;
if($count == 1) {
?>
<!--First post -->
<h4 class="cat-title"><?php $category = get_the_category(); echo $category[0]->cat_name; ?></h4>
<div class="post-image">
<img src="<?php bloginfo( 'template_url' ); ?>/upload/imagepost1.jpg" alt="">
</div>
<div class="post-container">
<h2 class="post-title">Create a Flexible Folded Paper Effect Using CSS3 Features</h2>
<div class="post-content">
<p>Venenatis volutpat orci, ut sodales augue tempor nec. Integer tempus ullamcorper felis eget dipiscing. Maecenas orci justo, mollis at tempus ac, gravida non</p>
</div>
</div>
<div class="post-meta">
<span class="comments">24</span>
<span class="author">nextwpthemes</span>
<span class="date">13 Jan 2013</span>
</div>
<!-- End of first post -->
<?php
}
//only on second post/loop
if($count == 2) {
?>
<!-- Second and others posts -->
<div class="other-posts">
<ul class="no-bullet">
<?php
}
if($count >= 2) { //Contador
?>
<!-- Repeat this list with post 2, 3, and 4 -->
<li id="<?php echo $post->ID; ?>">
<img src="<?php bloginfo( 'template_url' ); ?>/upload/thumb1.jpg" alt="">
<h3 class="post-title">Check Out the New Recommended Resources on Webdesigntuts+</h3>
<span class="date">13 Jan 2013</span>
</li>
<?php
}
//again, only on final loop
if($count == $perpage) {
?>
</ul>
</div>
<?php
}
}
?>
</article>
That will only output one li in the second loop, and by the end of $perpage (i keep those 4 perpage you ask to the original WP_Query).
It's ugly, but should works.
I am using jquery ui's tabs
And i want to make it dynamic by getting the tabs from a mysql database using php , but not sure how to add the fragment 1 , 2 , 3 according to the number of rows of the table i have.
For example , there's 5 rows , that means there's 5 fragment. here's the html code for the jquery ui.
<div id="featured" >
<ul class="ui-tabs-nav">
<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1"><img class="thumb" src="http://upload.wikimedia.org/wikipedia/en/thumb/0/0f/Avs38.jpg/250px-Avs38.jpg" alt="" /><span>15+ Excellent High Speed Photographs</span></li>
<li class="ui-tabs-nav-item" id="nav-fragment-2"><img class="thumb" src="http://www.crunchbase.com/assets/images/original/0007/5132/75132v1.jpg" alt="" /><span>20 Beautiful Long Exposure Photographs</span></li>
</ul>
<!-- First Content -->
<div id="fragment-1" class="ui-tabs-panel" style="">
<img src="image.jpg" alt="" />
<div class="info" >
<h2><a href="#" >Loerm Ipsum</a></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>
</div>
</div>
</div>
Normally i would use this php code to echo out database
<?php
$rows = array();
while($row = mysql_fetch_array( $query )){
$rows[] = $row;
echo "'Some html code data $row[image] test'\n";
}
}
?>
However if i use this code , it will generate a html like :
<div id="fragment-1" class="ui-tabs-panel" style="">
<img src="image.jpg" alt="" />
<div class="info" >
<h2><a href="#" >Loerm Ipsum</a></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>
</div>
</div>
<div id="fragment-1" class="ui-tabs-panel" style="">
<img src="image2.jpg" alt="" />
<div class="info" >
<h2><a href="#" >Loerm Ipsum2</a></h2>
<p>L2222<a href="#" >read more</a></p>
</div>
</div>
As you can see , it does not make the second fragment , fragment TWO.
I want the results to be like this:
<div id="fragment-1" class="ui-tabs-panel" style="">
<img src="image.jpg" alt="" />
<div class="info" >
<h2><a href="#" >Loerm Ipsum</a></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>
</div>
</div>
<div id="fragment-2" class="ui-tabs-panel" style="">
<img src="image2.jpg" alt="" />
<div class="info" >
<h2><a href="#" >Loerm Ipsum2</a></h2>
<p>L2222<a href="#" >read more</a></p>
</div>
</div>
So how can i do this?
<?php
$rows = array();
$frag = 1;
while($row = mysql_fetch_array( $query )){
$rows[] = $row;
echo "fragment-$frag";
echo "'Some html code data $row[image] test'\n";
$frag++;
}
}
?>
If you are talking about initial loading of the tabs, then modify your code to have a counter, and output the value of that counter to the tab fragment as follows:
<?php
$count = 0; // Initialize counter
$rows = array();
while($row = mysql_fetch_array( $query )) {
$rows[] = $row;
echo '<div id="fragment-' . ++$count . '" class="ui-tabs-panel" style="">';
echo "'Some html code data $row[image] test'\n";
}
?>