Tabs to navigate page by page - php

I use bootstrap with JQuery and I would like to use tabs to navigate page by page.
Indeed, I have some results in a table. With SQL, I know how to do this by using LIMITE 1,10 for example. And by using a $_GET argument to navigate page by page...
But here, I would like use tabs instead.
Here is my code:
echo '<div class="tab-content">';
echo '<div class="tab-pane fade in active" id=1>';
while($row = $selectAllUsersM->fetch(PDO::FETCH_OBJ)){
$isActive = ($row->Activation) ? 'Desable' : 'Enable';
echo "<tr>"; echo '<td>'.$row->Firstname.'</td>';
echo '<td>'.$row->Name.'</td>';
echo '<td>'.$row->Nickname.'</td>';
echo '<td>'.$row->Email.'</td>';
echo '<td>'.timeToDDMMYYYY($row->DateInscription).'</td>';
echo '<td><a href="?param='.$row->Activation.'&id='.$row->IdUser.'" title='.$isActive.'>'.isActive($row->Activation).'</a></td>';
echo "</tr>";
}
echo '</div>';
echo '</div>';
Here is the example for pagination:
<ul class="pagination">
<li>«</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>»</li>
</ul>
I don't know how can I display 10 results on each page. Then, if 11 results, create a new page and a new tab. I hope you know what I mean.
Thank you for your help ;)

Well, I solved this by using a POST in Ajax.
Function to display results
<script>
function displayPilotesF(pageF) {
$.post("pilotesF.php",
{ page : pageF},
function(data){
//alert("Data Loaded: " + data);
$("#pilotesF").html(data);
}
);
}
</script>
I display the results in a div:
<div id="pilotesF"></div>
And on my page "pilotesF.php":
if(isset($_POST['page'])){
$page = $_POST['page'];
$selectAllUsersF= getAllInfoOfAllUsersF($page, nbPiloteFPerPage);
$selectAllUsersF->execute();
echo "<table class='table table-hover table-condensed'>";
echo "<th>Firstname</th>";
echo "<th>Name</th>";
echo "<th>Nickname</th>";
echo "<th>Email</th>";
echo "<th>Registration</th>";
echo "<th>State account</th>";
while($row = $selectAllUsersF->fetch(PDO::FETCH_OBJ)){
$isActive = ($row->Activation) ? 'Disable' : 'Enable';
echo "<tr>";
echo '<td>'.$row->Firstname.'</td>';
echo '<td>'.$row->Name.'</td>';
echo '<td>'.$row->Nickname.'</td>';
echo '<td>'.$row->Email.'</td>';
echo '<td>'.timeToDDMMYYYY($row->DateInscription).'</td>';
echo '<td><a href="?param='.$row->Activation.'&id='.$row->IdUser.'" title='.$isActive.'>'.isActive($row->Activation).'</a></td>';
echo "</tr>";
}
echo "</table>";
}
And for my pagination:
$nbPages= ceil($nbPiloteF/ nbPiloteFPerPage);
echo '<div class="text-center">';
echo '<ul class="pagination" id="tabs2">';
/***********************************/
for ($i = 1 ; $i <= $nbPages; $i++){
if($i == 1)
echo '<li class="active"><a data-toggle="tab" OnClick="displayPilotesF('.$i.');">'.$i.'</a></li>';
else
echo '<li><a data-toggle="tab" OnClick="displayPilotesF('.$i.');">'.$i.'</a></li>';
}
/***********************************/
echo '</ul>';
echo '</div>';
Maybe it could help some of you guys,
Thank you anyway, have a night! :)

Related

Locations display ossclas

I use osclass and I have this code for display regions and their cities. All working good but I need display regions and cities only with items, how can i do it? Please help me i'm beginner.
<?php
$aRegions = Region::newInstance()->getByCountry('AT');
if(count($aRegions) > 0 ) {
?>
<ul>
<?php
foreach($aRegions as $region) {
//print_r ($region);
echo "<li>";
//$region['pk_i_id'].
?>
<div class="accordionButton">
<a href="javascript:void()">
<?php echo $region['s_name']."\n"; ?>
</a>
<?php // echo "</em>(". $region['items'].")</em>";?>
</div>
<?php
$aCities = City::newInstance()-> getByRegion($region['pk_i_id']);
if(count($aCities) > 0 ) {
echo "<div class=\"accordionContent\">";
echo "<ul>";
foreach($aCities as $city) {
// print_r ($city);
//$city["pk_i_id"].'
echo "<li>";
echo "<a href='". osc_search_url( array( 'sRegion'=>$region["s_name"], 'sCity' => $city['s_name'] ) ) ."'> ";
echo $city["s_name"]."\n";
echo "</em>(". $city['items'].")</em>";
echo "</a>";
echo "</li>";
}
}
echo "</ul>";
echo "</li>";
}
?>

Changing active class using echo in php comand

I have a problem with next code:
<?php
include("db.php");
$sql = mysql_query("SELECT COUNT(id_produs) FROM My_Products WHERE `id_produs_categorie`='$id_categorie' ");
$total_produse = mysql_result($sql, 0);
$total_pagini = ceil($total_produse / $produse_pe_pagina);
if(isset($_GET['ID'])!="")
$id_categorie=$_GET['ID'];
echo '<div class="row">';
echo '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">';
echo '<div class="bs-example margin-top20">';
echo '<ul class="pagination">';
echo '<li class="disabled"></li>';
echo '<li ( basename($_SERVER["REQUEST_URI"]) == "categorie.php?ID=$id_categorie&pagina=1" ? class="active" : "" )>1</li>';
for ($i=2; $i<=$total_pagini; $i++) {
echo '<li ( basename($_SERVER["REQUEST_URI"]) == "categorie.php?ID=$id_categorie&pagina=$i" ? class="active" : "" )>'.$i.'</li>';
};
echo '<li class="disabled"></li>';
echo '</ul>';
echo '</div>';
echo '</div>';
echo '</div>';
?>
I'm trying to change the classes based on the page user is on.
The code is good if i echo the address its ok with variables but the problem is that even if i'm on page 1 it adds also the class active to page 2 or 3.
What i'm doing wrong here?
Thank you for your help!
Try:
<?php
include("db.php");
$sql = mysql_query("SELECT COUNT(id_produs) FROM My_Products WHERE `id_produs_categorie`='$id_categorie' ");
$total_produse = mysql_result($sql, 0);
$total_pagini = ceil($total_produse / $produse_pe_pagina);
if(isset($_GET['ID'])!="")
$id_categorie=$_GET['ID'];
if(isset($_GET['pagina'])!="")
$pagina = $_GET['pagina'];
echo '<div class="row">';
echo '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">';
echo '<div class="bs-example margin-top20">';
echo '<ul class="pagination">';
echo '<li class="disabled"></li>';
for ($i=1; $i<=$total_pagini; $i++) {
$class = $pagina == $i ? 'class="active"' : "";
echo '<li ' . $class .'>'.$i.'</li>';
};
echo '<li class="disabled"></li>';
echo '</ul>';
echo '</div>';
echo '</div>';
echo '</div>';
?>

Insert Clear Fix After Certain Amount of DIVs in PHP

I'm struggling with a problem and I thought someone could help me. I'm trying to insert a clear div after a certain amount div containers. Now in this example I've managed to get it to work that after the first three a clear div is placed, but I want it to be inserted after each set of 3 divs depending on how many featured articles I've setup (3, 6, 9 etc).
$featured_articles = get_field('featured_articles', false, false );
$id = $featured_articles[0];
//var_dump();
$numberOfArticles = count($featured_articles);
//var_dump($featured_articles);
echo "<div class='container'>";
echo "<div class='row-fluid'>";
for ($i=0; $i < $numberOfArticles; $i++) {
if ($featured_articles) {
$id = $featured_articles[$i];
//var_dump($featured_articles);
if ( has_post_thumbnail($id) ) {
echo "<div class='span4'>";
echo "<article class='post__holder recipes'>";
echo "<a href='".get_permalink($id)."' class='image'>";
echo get_the_post_thumbnail( $id, 'medium-thumb' );
$image_large = wp_get_attachment_image_src( get_post_thumbnail_id($id), 'large');
echo "</a>";
}
echo "<a href='".get_permalink($id)."'><h3>".get_the_title($id)."</h3></a>";
echo "<div class='starRating'>";
echo "<img src='".home_url()."/wp-content/themes/BUZZBLOG-theme/images/StarRating.svg' alt='Testergebnis'>";
echo "<div class='bar' style='width:".get_field('rating', $id)."%'></div>";
echo "</div>";/** end starrating **/
echo "<a href='".get_permalink($id)."'><div class='readmore-button'>Zum Testbericht...</div></a>";
echo "</div>";
echo "</article>";
if ($i >= 2) {
if($i == 2) {
echo "<div class='clearfix'>";
}
if ($i == $numberOfArticles) {
echo "</div>";
}
}
}
}
echo "</div>";
echo "</div>";
Try this It will check for multiples of 3 and place a clearfix div
Also dont forget to start the $i from 1 upto $i <= $numberOfArticles
$featured_articles = get_field('featured_articles', false, false );
$id = $featured_articles[0];
//var_dump();
$numberOfArticles = count($featured_articles);
//var_dump($featured_articles);
echo "<div class='container'>";
echo "<div class='row-fluid'>";
for ($i=1; $i <= $numberOfArticles; $i++) {
if ($featured_articles) {
$id = $featured_articles[$i-1];
//var_dump($featured_articles);
if ( has_post_thumbnail($id) ) {
echo "<div class='span4'>";
echo "<article class='post__holder recipes'>";
echo "<a href='".get_permalink($id)."' class='image'>";
echo get_the_post_thumbnail( $id, 'medium-thumb' );
$image_large = wp_get_attachment_image_src( get_post_thumbnail_id($id), 'large');
echo "</a>";
}
echo "<a href='".get_permalink($id)."'><h3>".get_the_title($id)."</h3></a>";
echo "<div class='starRating'>";
echo "<img src='".home_url()."/wp-content/themes/BUZZBLOG-theme/images/StarRating.svg' alt='Testergebnis'>";
echo "<div class='bar' style='width:".get_field('rating', $id)."%'></div>";
echo "</div>";/** end starrating **/
echo "<a href='".get_permalink($id)."'><div class='readmore-button'>Zum Testbericht...</div></a>";
echo "</div>";
echo "</article>";
if($i%3==0) {
echo "<div class='clearfix'></div>";
}
}
}
echo "</div>";
echo "</div>";
You can do like this:-
for ($i=0; $i < $numberOfArticles; $i++) {
// your code
if($i%3==0) echo '<div class="clearfix"></div>';
}
You can use array_chunk() function to divide your array in group of 3 members each and you can iterate over each array.
PHP is a server side scripting language that is embedded in HTML.
So use this feature in your code instead of writing echo "html element" every where in code.
I think you have miss match of div element. Because <article> must be close before the <div class='span4'> but in your code it is not there.
$featured_articles = get_field('featured_articles', false, false );
$dividedIn3GroupsEach = array_chunk($featured_articles, 3);
foreach ($dividedIn3GroupsEach as $array) {
?>
<div class='container'>
<div class='row-fluid'>
<?php
foreach ($array as $key => $value) {
$id = $featured_articles[$key];
if (has_post_thumbnail($id)) {
?>
<div class='span4'>
<article class='post__holder recipes'>
<a href='<?php echo get_permalink($id); ?>' class='image'>
<?php
echo get_the_post_thumbnail($id, 'medium-thumb');
$image_large = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'large');
?>
</a>
<?php } ?>
<a href='<?php echo get_permalink($id); ?>'><h3><?php echo get_the_title($id); ?></h3></a>
<div class='starRating'>
<img src='<?php echo home_url() ?>"/wp-content/themes/BUZZBLOG-theme/images/StarRating.svg' alt='Testergebnis'>
<div class='bar' style='width:<?php echo get_field('rating', $id); ?>%'></div>
</div>
<a href='<?php echo get_permalink($id); ?>'><div class='readmore-button'>Zum Testbericht...</div></a>
</article>
</div>
<?php }
?>
</div> <!-- row-fluid end -->
</div> <!-- container end -->
<div class='clearfix'></div>
<?php } ?>
I hope this may help you.

Wordpress Ordering (boolean?)

Hi I would like to order custom fields in wordpress. I've got it displaying the single project. But can't figure out how I can get it to display in order. I've created a field called project_order which works correctly on another page.
But i'm not used to this sort of php with order by. This is a project designed by someone else so i'm trying to pick up and learn how it was built.
<?php
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
?>
I'm guessing it will have something to do with.
$rows = get_field('projects', $sector [$post->post_name]);
Try below code, may be this resolve your problem.
<?php
wp_reset_query();
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
wp_reset_query();
?>
Thanks.

How to Detect a Button Click in an Expanded Accordion Row with Multiple Labels

This is an extension to another post by myself (How To Detect a Button Click in the Expanded Accordion Row).
After adding some additional rows in the details section of my accordion control and moving the 'Select' button into a separate div, I am only getting the values from the first accordion row. This was my original issue. Just to confirm the original solution worked, if I move my 'Select' button into the save div containing the label for Location, it passes the correct location label ('labelAccordionLocation') value for what ever row I have expanded but always passes the first row's name label value. It also works correct if the 'Select' button is in the save div as the Name label ('labelAccordionName').
Based on the suggestion in my other post (which worked flawlessly for my original example), it seems that I now need to figure out how to identify the div that contains each label so I can then pass it's value when the 'Submit' button is clicked. Although, this is still just an amateur's way of thinking.
<div class="accordion" id="accordion2">
<?php
// SQL stuff here...
$group = null;
while ($row = odbc_fetch_array($db)) {
if ($row['Name'] != $group) {
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse'
data-parent='#accordion2' href='#", $row['Number'],"'>
<button id='buttonAccordionToggle'
data-target='#", $row['Number'],"'>", $row['Name'],"</button></a>";
echo "</div>";
echo "<div id='", $row['Number'],"' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<div class='control-group' style='min-height: 50px'>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Name:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label id='labelAccordionName'>",
$row['Name'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Location:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label id='labelAccordionLocation'>",
$row['Location'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<a id='select' class='btn'>Select</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
$group = $row['Name'];
}
}
}
?>
</div>
<div id="divDetails" style="display: none;">
<label>Name:</label>
<label id="labelName"></label><br />
<label>Location:</label>
<label id="labelLocation"></label><br />
<a id="close" class="btn">Close</a>
</div>
<script>
// Hide the accordion and show the hidden div
$('a.btn').click(function() {
$('#accordion2').hide();
$('#divDetails').show();
// Pass the label value from the accordion row to the hidden div label
$('#labelName').html($('.accordion-body.in .labelAccordionName').html());
$('#labelLocation').html($('.accordion-body.in .labelAccordionLocation').html());
});
// Hide the div and show the accordion again
$('#close').click(function() {
$('#accordion2').show();
$('#divDetails').hide();
});
// Only allows one row to be shown at a time
$('.accordion-toggle').click(function() {
var $acc = $('#accordion2');
$acc.on('show', '.collapse', function() {
$acc.find('.collapse.in').collapse('hide');
});
});
$(document).ready(function(){
// On dropdown change, pass in value to populate accordion/details
$('#dd').change(function() {
var r = $(this).val();
location.href = "test.php?src=" + r;
});
});
</script>
I did some searching on the jQuery site to try and figure this one out but unfortunately was unable to get it working. I'll do my best to give any additional information that is needed.
Edits
I changed the label's to use classes instead of id's. Although a great suggestion, I did not have to apply a new class 'activeAccordion'. Since the class 'in' is applied to the expanded row, I was able to use it for access as seen below. I also updated the jsFiddle and provided a link at the bottom.
$('a.btn').click(function() {
$('#accordion2').hide();
$('#divDetails').show();
$('#labelName').html($('.accordion-body.in .labelAccordionName').html());
$('#labelLocation').html($('.accordion-body.in .labelAccordionLocation').html());
});
Working jsFiddle
http://jsfiddle.net/N8JuQ/
You should consider escaping out of PHP in your if statement and only jump back in to echo the variables. Also read up on alternative syntax: http://php.net/manual/en/control-structures.alternative-syntax.php
while ($row = odbc_fetch_array($db)) {
if ($row['Name'] != $group){
?>
<div class='accordion-heading'>
<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion2' href='#", <?php echo $row['Number']; ?>,"'>
<button id='buttonAccordionToggle' data-target='#", <?php echo $row['Number']; ?>,"'>", <?php echo $row['Name']; ?>,"</button></a>
</div>
<div id='", <?php echo $row['Number']; ?>,"' class='accordion-body collapse'>
<div class='accordion-inner'>
...
...
...
<?php
}
?>
when generating html with php, as long as you are iterating be careful with IDs. Never generate same ID in a DOM, it messes things really bad. (ie. select, labelAccordionName, buttonAccordionToggle) I suggest using classes or generating unique IDs plus a generic class
you should have something like :
<div class="accordion" id="accordion2">
<?php
// SQL stuff here...
$group = null;
while ($row = odbc_fetch_array($db)) {
if ($row['Name'] != $group) {
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse'
data-parent='#accordion2' href='#", $row['Number'],"'>
<button class='buttonAccordionToggle'
data-target='#", $row['Number'],"'>", $row['Name'],"</button></a>";
echo "</div>";
echo "<div id='", $row['Number'],"' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<div class='control-group' style='min-height: 50px'>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Name:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label class='labelAccordionName'>",
$row['Name'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Location:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label class='labelAccordionLocation'>",
$row['Location'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<a class='select btn'>Select</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
$group = $row['Name'];
}
}
}
?>
</div>
<div id="divDetails" style="display: none;">
<label>Name:</label>
<label id="labelName"></label><br />
<label>Location:</label>
<label id="labelLocation"></label><br />
<a id="close" class="btn">Close</a>
</div>
<script>
something like that, didn't check as you don't provided a jsfiddle. As for your data to retrieve correctly, I would suggest adding a class on active accordion-body then in your finds use this class to select the correct element :
$('.accordion-toggle').click(function() {
var $acc = $('#accordion2');
$('.activeAccordion').removeClass('activeAccordion');
$(''+$(this).next('.buttonAccordionToggle').data('target')).addClass('activeAccordion');
$acc.on('show', '.collapse', function() {
$acc.find('.collapse.in').collapse('hide');
});
});
then use this new class :
$('#labelName').html($('accordion-body.activeAccordion .labelAccordionName').html()));
$('#labelLocation').html($('accordion-body.activeAccordion .labelAccordionLocation').html()));

Categories