How to Active Loop Tab PHP - php

I don't know what to do loop and active tab on php.Active only one tab at a time.
My tab
<div class="container content">
<div class="row tab-v3">
<div class="col-sm-3">
<?php do { ?>
<ul class="nav nav-pills nav-stacked">
<li><i></i><?php echo $row_menulist['mlname']; ?></li>
</ul>
<?php } while ($row_menulist = mysql_fetch_assoc($menulist)); ?>
</div>
<div class="col-sm-9">
<div class="tab-content">
<div class="tab-pane fade in active" id="<?php echo $row_menulist['mlname']; ?>">
<?php do { ?>
<h4><?php echo $row_info['mlname']; ?></h4>
<p><?php echo $row_info['detail']; ?></p>
<?php } while ($row_info = mysql_fetch_assoc($info)); ?>
</div>
</div>
</div>
</div>
</div>

remove active class,i assume that change in loop not affect in design.
<div class="container content">
<div class="row tab-v3">
<div class="col-sm-3">
<?php do { ?>
<ul class="nav nav-pills nav-stacked">
<li><i></i><?php echo $row_menulist['mlname']; ?></li>
</ul>
<?php } while ($row_menulist = mysql_fetch_assoc($menulist)); ?>
</div>
<div class="col-sm-9">
<div class="tab-content">
<?php $count = 1; do { ?>
<div class="tab-pane fade in <?php if($count == '1') { echo 'active'; } ?>" id="<?php echo $row_menulist['mlname']; ?>">
<h4><?php echo $row_info['mlname']; ?></h4>
<p><?php echo $row_info['detail']; ?></p>
</div>
<?php $count++; } while ($row_info = mysql_fetch_assoc($info)); ?>
</div>
</div>
</div>
</div>

It's working!
I even use the same logic into a CMS PHP Based (SPIP).
<div class="row">
<div class="col-xs-12 col-sm-3">
<div class="w-100 srvc-tab">
<ul class="nav nav-tab">
<?php $count = 1; ?>
<BOUCLE_getServiceTitle (ARTICLES){id_rubrique=#ID_RUBRIQUE}{par id_article}{tous}>
<li class="<?php if($count == '1') { echo 'active'; } ?>">
<a href="#service-#COMPTEUR_BOUCLE" data-toggle="tab">
[(#TITRE)]
</a>
</li>
<?php $count++; ?>
</BOUCLE_getServiceTitle>
</ul>
</div>
</div>
<div class="col-xs-12 col-sm-9">
<div class="w-100 tab-content">
<?php $count = 1; ?>
<BOUCLE_getServiceContent (ARTICLES){id_rubrique=#ID_RUBRIQUE}{tous}>
<div id="service-#COMPTEUR_BOUCLE" class="col-xs-12 tab-pane fade in <?php if($count == '1') { echo 'active'; } ?>">
<div class="w-100 mb-15 pb-15">
<h3 class="mb-0 text-capitalize fw-600">
[(#TITRE)]
<span class="d-inline-block stroke"></span>
</h3>
</div>
<div class="w-100">
[(#TEXTE)]
</div>
</div>
<?php $count++; ?>
</BOUCLE_getServiceContent>
</div>
</div>
<div class="clearfix"></div>
</div>

Related

Dynamically add active class to an acf group

How Can i add dynamically active class in this code? I have tried using $i=0 in nested if loop with $i== at end of nested is loop. but it seems not working.
<div class="tab-content mt-5">
<?php
if (have_rows('whats_included', 2959)) {
while (have_rows('whats_included', 2959)) {
the_row();
if (have_rows('list_data', 2959)) {
while (have_rows('list_data', 2959)) {
the_row();
?>
<div id="<?= the_sub_field('id'); ?>" class="container tab-pane active"><br>
<div class="row align-items-center justify-content-center">
<div class="col-lg-8">
<div class="talabat-clone-wrap radius5">
<img src="<?= bloginfo('template_directory') ?>/assets/images/talabat-app/triangle.png" class="triangle-shape" alt="">
<p><?= the_sub_field('text'); ?></p>
</div>
</div>
</div>
</div>
<?php
}
}
}
}
?>
</div>
I have solved the issue,thank you.
<div class="tab-content mt-5">
<?php
$i = 0;
if (have_rows('whats_included', 2959)) {
while (have_rows('whats_included', 2959)) {
the_row();
if (have_rows('list_data', 2959)) {
while (have_rows('list_data', 2959)) {
the_row();
?>
<div id="<?= the_sub_field('id'); ?>" class="container tab-pane <?php if ($i++ == 1) : echo 'active';endif; ?>"><br>
<div class="row align-items-center justify-content-center">
<div class="col-lg-8">
<div class="talabat-clone-wrap radius5">
<img src="<?= bloginfo('template_directory') ?>/assets/images/talabat-app/triangle.png" class="triangle-shape" alt="">
<p><?= the_sub_field('text'); ?></p>
</div>
</div>
</div>
</div>
<?php
}
}
}
}
?>
</div>

Show Data database only with specific ID

I have this code to show all data in my database:
<?php foreach($alldatas as $data): ?>
<div class="col-md-4">
<div class="card">
<div class="content">
<h3><?php echo $data['data_name'];?></h3>
<div class="footer text-center">
<?php echo $data['data_version'];?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
That code works perfect to show all my data with different data_name and data_version. But what I want is to show the data only with specific ID.
So I want to make it work with bootstrap navtabs:
<div class="col-md-12">
<ul class="nav nav-pills nav-tabs nav-justified" role="tablist">
<li role="presentation" class="active">Pro</li>
<li role="presentation">Middle</li>
<li role="presentation">Low</li>
</ul>
</div>
<?php foreach($alldatas as $data): ?>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="pro">
<?php if($data['id'] == "2" | $data['id'] == "3" | $data['id'] == "4"){?>
<div class="col-md-4">
<div class="card">
<div class="content">
<h3><?php echo $data['data_name'];?></h3>
<div class="footer text-center">
<?php echo $data['data_version'];?>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<div role="tabpanel" class="tab-pane fade" id="middle">
<?php if($data['id'] == "5" | $data['id'] == "6" | $data['id'] == "7"){?>
<div class="col-md-4">
<div class="card">
<div class="content">
<h3><?php echo $data['data_name'];?></h3>
<div class="footer text-center">
<?php echo $data['data_version'];?>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php endforeach; ?>
But it just only show data with ID 1,2,3 when I try to click other tabs. How to fix this?
You are having foreach loop on "tab-content" which is wrong, actually, it will create so many "tab-content"s and that's not required. You MUST loop for content not "tab-content".
So, first fix would be:
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="pro">
<?php foreach($alldatas as $data): ?>
<?php if($data['id'] == "2" | $data['id'] == "3" | $data['id'] == "4"){?>
<div class="col-md-4">
<div class="card">
<div class="content">
<h3><?php echo $data['data_name'];?></h3>
<div class="footer text-center">
<?php echo $data['data_version'];?>
</div>
</div>
</div>
</div>
<?php } ?>
<?php endforeach; ?>
</div>
<div role="tabpanel" class="tab-pane fade" id="middle">
<?php foreach($alldatas as $data): ?>
<?php if($data['id'] == "5" | $data['id'] == "6" | $data['id'] == "7"){?>
<div class="col-md-4">
<div class="card">
<div class="content">
<h3><?php echo $data['data_name'];?></h3>
<div class="footer text-center">
<?php echo $data['data_version'];?>
</div>
</div>
</div>
</div>
<?php } ?>
<?php endforeach; ?>
</div>
</div>
It will resolve your issue, however, if it still persists, you can implement a jquery function for custom toggling of "active" class. (Still, first correct the position of "foreach" as shown above).

Error when displaying webpage in columns

I am doing a dynamic site in php. I have divided the page into 2 columns. The first section shows a person's profile and the second section shows the article written by him/her. The problem is when i am adding more than one article. The second article is coming below the profile. I have tried using class clearfix. Its not working. Can someone please help me?
This is my page
<div class="container">
<?php
session_start();
$q = $_SESSION['id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("demo_db",$con);
$sql="select * from personal_details where id=$q";
$res=mysql_query($sql);
while($ar=mysql_fetch_array($res))
{
?>
<div>
<div class="row">
<div style="background-color:rgba(125, 178, 194, 0.43); margin-bottom:10px;" class="col-sm-8 col-md-8 col-lg-8">
<div class="row">
<div class="col-sm-4 col-md-4 col-lg-4">
<img style="margin:20px;" src="uploads/<?php echo $ar[17]; ?>">
</div>
<div class="col-sm-8 col-md-8 col-lg-8">
<h3><b>Dr. <?php echo $ar[1];?></b></h3>
<h5><?php echo $ar[8];?>, <?php echo $ar[12];?></h5>
<h5><?php echo $ar[2];?>, <?php echo $ar[7];?> years of experience</h5>
<p><?php echo $ar[16];?></p>
</div>
</div>
<div style="margin:20px;">
<h4><b>Services</b></h4>
<hr>
<ul>
<li>
<h5><?php echo $ar[18]; ?></h5>
</li>
</ul>
<h4><b>Specialisations</b></h4>
<hr>
<ul>
<li>
<h5><?php echo $ar[2]; ?></h5>
</li>
</ul>
<h4><b>Education</b></h4>
<hr>
<ul>
<li>
<h5><?php echo $ar[8]; ?> - <?php echo $ar[9]; ?> , <?php echo $ar[10]; ?> , <?php echo $ar[11];?></h5>
</li>
</ul>
<ul>
<li>
<h5><?php echo $ar[12]; ?> - <?php echo $ar[13]; ?> , <?php echo $ar[14]; ?> , <?php echo $ar[15];?></h5>
</li>
</ul>
</div>
</div>
<div class="col-sm-4 col-md-4 col-lg-4">
<h3>Articles by <?php echo $ar[1];?></h3><?php } ?>
<hr>
<?php
$sql1="select * from article_tb where id=$q";
$res1=mysql_query($sql1);
while($ar=mysql_fetch_array($res1))
{
$_SESSION['id'] = $q;
?>
<h4><b><?php echo $ar[1]; ?></b></h4>
<div class="row">
<div class="col-sm-7 col-lg-7 col-md-7">
<img src="uploads/<?php echo $ar[3]; ?>" width="170px" height="88">
</div>
<div class="col-sm-5 col-md-5 col-lg-5">
<form action="blog.php">
<input type="submit" class="btn btn-info" name="read" value="read" />
</form>
</div>
</div>
<hr>
</div>
<?php } ?>
</div>
</div>

Yii - foreach output exceeds 12 columns

I'm having a problem right now where my data exceeds 12 columns and it's looking distorted.
I tried to fiddle around with my foreach position and add clearfix but it doesn't work. How do I make sure that it will not exceed 12? Is it because there's 2 foreach in a row?
<div class="row">
<?php $count=0; foreach($model['organizations']['approve'] as $organization): ?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Manage</span>
<h3 class=""><?php echo $organization->title ?></h3>
</div>
<div class="ibox-content">
<?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
<span class="label label-primary pull-right">Visit</span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php $count++; endforeach; ?>
<div class="clearfix"></div>
<?php $count=0; foreach($model['organizations']['pending'] as $organization): ?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right badge badge-warning" ">Pending</span>
<!-- <?php echo Html::image(ImageHelper::thumb(50, 50, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive")); ?>
-->
<h3 class="no-margins"><?php echo $organization->title ?></h3>
<!-- <small><?php echo $organization->text_oneliner ?></small>
-->
</div>
<div class="ibox-content">
<?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
<span class="label label-primary pull-right">Visit</span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php $count++; endforeach; ?>
<div class="col-lg-4">
<div class="contact-box full-width light-green-bg">
<div class="col-xs-12">
<div class="center-block text-center margin-top-lg text-muted">
<i class="fa fa-plus-circle fa-2x"></i><br />Add
</div>
</div>
</div>
</div>
</div>
Any help would be greatly appreciated!
Hey try put this code before <div class="clearfix"></div>:
<?php
$count = 1;
foreach ($model['organizations']['approve'] as $organization) {
if ($count == 1 || $count % 3 == 1) {
?>
<div class="row">
<?php
}
?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Manage</span>
<h3 class=""><?php echo $organization->title ?></h3>
</div>
<div class="ibox-content">
<?php /*echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive"));*/ ?>
<span class="label label-primary pull-right"><a
href="<?php echo $organization->url_website ?>"
class=" <?php echo empty($organization->url_website) ? 'disabled' : '' ?>"
target="_blank">Visit</a></span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php
if ($count % 3 == 0) {
?>
</div>
<?php }
$count++;
}
?>
<?php if ($count % 3 != 0) echo "</div>"; ?>
You can try our this. I just modified #Sador's answer. I hope it helps.
<div class="row">
<?php
$count = 1;
foreach ($model['organizations']['approve'] as $organization):
?>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary pull-right">Manage</span>
<h3 class=""><?php echo $organization->title ?></h3>
</div>
<div class="ibox-content">
<?php /* echo Html::image(ImageHelper::thumb(64, 64, $organization->image_logo), Yii::t('app', 'Logo Image'), array('class'=>"img-circle m-t-xs img-responsive")); */ ?>
<span class="label label-primary pull-right">
Visit
</span>
<h6 class="no-margins">Website</h6>
</div>
<!-- <div class="btn-group btn-group-xs btn-group-justified">
Manage
Website
</div> -->
</div>
</div>
<?php if ($count % 3 == 0) { ?>
</div>
<div class="row">
<?php
}
$count++;
endforeach;
?>

How to set only first item active on while loop in php

i using slider fetch MYSQL records i using while function i need only active class in first item only. i need only active class in loop first element.how to solve this problem. i using this code but can't change the item.
mycode
<?php
$qry = MYSQL_QUERY("SELECT * FROM `post` WHERE `post_type`='events' AND `post_event_start_date` <= CURDATE() ORDER BY `post_event_start_date`");
?>
<?php while( $row = MYSQL_FETCH_OBJECT($qry) ){ ?>
<div class="item <?php if($i==0) { ?> active<?php } ?>">
<ul class="thumbnails">
<li class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
<div class="fff">
<div class="thumbnail">
<img src="administrator/slide_name/large/slide_1.jpg" alt="">
</div>
<div class="col-lg-12 well">
<div class="form-group">
<h3><?php print_r($row->post_title); ?></h3>
</div>
<div class="form-group">
<h4><?php print_r($row->post_url); ?></h4>
<h5></h5>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<center><p>Start Date & Time</p><?php print_r($row->post_event_start_date); ?></center>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<center><p>Start End & Time</p><?php print_r($row->post_event_end_date); ?></center>
</div>
</div>
</div>
<div class="form-group">
<p>Location:</p>
<p><?php print_r($row->post_maplocation); ?></p>
</div>
<div class="form-group">
<p>Description: </p>
<p><?php print_r($row->post_desc); ?></p>
</div>
<div class="row pull-right">
<a class="btn btn-mini" href="#">» Read More</a>
<a class="btn btn-mini" href="#">» Share it</a>
</div>
</div>
</div>
</li>
</ul>
</div>
<?php } ?>
Replace
<?php while( $row = MYSQL_FETCH_OBJECT($qry) ){ ?>
<div class="item <?php if($i==0) { ?> active<?php } ?>">
With
<?php
$i=0;
while( $row = MYSQL_FETCH_OBJECT($qry) ){ ?>
<div class="item <?php if($i==0) {
$i=1;
echo 'active'; } ?>">
Try this.
$qry = MYSQL_QUERY("SELECT * FROM 'post' WHERE 'post_type'='events' AND 'post_event_start_date' <= CURDATE() ORDER BY 'post_event_start_date'");
$first_item = true;?>
<?php while( $row = MYSQL_FETCH_OBJECT($qry) ){ ?>
<div class="item <?php echo $first_item? 'active': ''; ?>"><?php $first_item = false; ?>
<ul class="thumbnails">
<li class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
<div class="fff">
<div class="thumbnail">
<img src="administrator/slide_name/large/slide_1.jpg" alt="">
</div>
<div class="col-lg-12 well">
<div class="form-group">
<h3><?php print_r($row->post_title); ?></h3>
</div>
<div class="form-group">
<h4><?php print_r($row->post_url); ?></h4>
<h5></h5>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<center><p>Start Date & Time</p><?php print_r($row->post_event_start_date); ?></center>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<center><p>Start End & Time</p><?php print_r($row->post_event_end_date); ?></center>
</div>
</div>
</div>
<div class="form-group">
<p>Location:</p>
<p><?php print_r($row->post_maplocation); ?></p>
</div>
<div class="form-group">
<p>Description: </p>
<p><?php print_r($row->post_desc); ?></p>
</div>
<div class="row pull-right">
<a class="btn btn-mini" href="#">» Read More</a>
<a class="btn btn-mini" href="#">» Share it</a>
</div>
</div>
</div>
</li>
</ul>
</div>
<?php } ?>`
Define $i = 0 and make it $i++
Try below code
<?php
$qry = MYSQL_QUERY("SELECT * FROM `post` WHERE `post_type`='events' AND `post_event_start_date` <= CURDATE() ORDER BY `post_event_start_date`");
?>
<?php
$i = 0;
while( $row = MYSQL_FETCH_OBJECT($qry) ){ ?>
<div class="item <?php if($i==0) { ?> active<?php } ?>">
<ul class="thumbnails">
<li class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
<div class="fff">
<div class="thumbnail">
<img src="administrator/slide_name/large/slide_1.jpg" alt="">
</div>
<div class="col-lg-12 well">
<div class="form-group">
<h3><?php print_r($row->post_title); ?></h3>
</div>
<div class="form-group">
<h4><?php print_r($row->post_url); ?></h4>
<h5></h5>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<center><p>Start Date & Time</p><?php print_r($row->post_event_start_date); ?></center>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<center><p>Start End & Time</p><?php print_r($row->post_event_end_date); ?></center>
</div>
</div>
</div>
<div class="form-group">
<p>Location:</p>
<p><?php print_r($row->post_maplocation); ?></p>
</div>
<div class="form-group">
<p>Description: </p>
<p><?php print_r($row->post_desc); ?></p>
</div>
<div class="row pull-right">
<a class="btn btn-mini" href="#">» Read More</a>
<a class="btn btn-mini" href="#">» Share it</a>
</div>
</div>
</div>
</li>
</ul>
</div>
<?php
$i++;
} ?>
<?php $i = 0 ;
$qry = MYSQL_QUERY("SELECT * FROM `post` WHERE `post_type`='events' AND `post_event_start_date` <= CURDATE() ORDER BY `post_event_start_date`");
?>
<?php while( $row = MYSQL_FETCH_OBJECT($qry) ){ ?>
<div class="item <?php if($i==0) { ?> active<?php } ?>">
Your other code
php $i++; } ?>

Categories