Angular JS ng-class or ng-if use - php

How I do following Code in angular JS
// PHP Code
<?php foreach($data as $key=>$row) {
if($key%2 == 0) { ?>
<div class="col 3"> Run this
<ul>
<?php } ?>
<li> Some Data </li>
<?php if($key%2 == 1) { ?>
</ul></div>
<?php } } ?>
I want to run above code in angular JS. any help appreciated.

Like this
<div ng-repeat="key in data">
<div ng-if="(key%2 == 0)" class="col 3"> Run this
<ul>
<li> Some Data </li>
</ul>
</div>
<div ng-if="(key%2 == 1)"> Run this
<ul>
<li> Some Data </li>
</ul>
</div>
</div>

Related

How can I dynamically fetch data in Tabs and Pills using their IDs? Using PHP & Codeigniter

I am creating a module for Question and Answers and I need to fetch the data separatedly each.
I created a Tab where I'll click the Question I want to answers, and its children or the answer should match.
For visual reference, here is my problem
I have this data that are all fetched, which should not be. That is why I created Tabs and Pills so I can separate questions and answers
12 and 13 are the id number of each data
So in Tabs and Pills, I got this
The problem of this, is that I cannot fetch the data dynamically, it just shows ID 13 data for question and answer. How can I change this dynamically so I can click back and forth the tabs and show the right data by its id?
I need to fetch the ID 12 of the 1st Tab
So here is my view
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<?php echo $question->id; ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane" id="13" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<?php if($answer->type_id==0): ?>
<input type="radio" name="question_<?php echo $question->id; ?>" value="<?php echo $answer->answer ?>" required/>
<?php echo $answer->answer; ?><hr>
<?php endif; ?>
<?php if($answer->type_id==1): ?>
<div class="input-group input-group-lg">
<input type="text" class="form-control col-md-6" placeholder="Enter Answer" name="question_<?php echo $question->id; ?>" required/>
</div>
<?php endif; ?>
<?php } ?>
</div>
</div><br>
</div>
</div>
Fix the tabs structure, your looping over questions for nav-item, but not looping over for tab-pane which is why clicking the tab link does nothing.
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php foreach($questions as $question){ ?>
<div class="tab-pane" id="tab-<?= $question->id ?>" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<!-- form input $answer / item -->
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>

Making a HTML section only visible to some people via PHP

I've made a section in HTML, but I want to be visible only to people who are if($Admin >= 1) from my database.
But I don't know how to write it.
This is my HTML so far.
!-- ADM SECTION -->
<div class="backimg" id="section-10">
<div class="bghover wow fadeInUp" data-wow-duration="1.5s" data-wow-delay=".5s">
<div class="grid flex16">
<div class="row paddtop5">
<h3 class="paraw wow fadeInUpBig" data-wow-duration="2s" data-wow-delay=".5s">ADMIN SECTION</h3>
<div class="admin">
<h3 data-wow-duration="2s" data-wow-delay=".5s"> Alege opțiunea </h3>
</div>
<!-- ban -->
<style>
ul.b {list-style-type: square;}</style>
<div class="ban">
<ul class="b">
<li>BAN SYSTEM</li>
<br>
<li>KICK SYSTEM</li>
<br>
<li>ADMIN JAIL SYSTEM</li>
<br>
</ul>
</div>
<div class="ban2">
<ul class="b">
<li>SEARCH SYSTEM</li>
<br>
<li>LOG SYSTEM</li>
<br>
<li>AWARD SYSTEM</li>
<br>
</ul>
</div>
<div class="ban3">
<ul class="b">
<li>MANAGAMENT SYSTEM</li>
<br>
<li>UNBAN SYSTEM</li>
<br>
<li>UNJAIL SYSTEM</li>
<br>
</ul>
</div>
Shall I add if($Admin >= 1) echo ? I want to show nothing to who has $admin lower than 1. And who has higher or equal than 1, to show that HTML part.
<?php if($Admin >= 1) { ?>
<!-- ADM SECTION -->
<div class="backimg" id="section-10">
<div class="bghover wow fadeInUp" data-wow-duration="1.5s" data-wow-delay=".5s">
<div class="grid flex16">
<div class="row paddtop5">
<h3 class="paraw wow fadeInUpBig" data-wow-duration="2s" data-wow-delay=".5s">ADMIN SECTION</h3>
<div class="admin">
<h3 data-wow-duration="2s" data-wow-delay=".5s"> Alege opțiunea </h3>
</div>
<!-- ban -->
<style>
ul.b {list-style-type: square;}</style>
<div class="ban">
<ul class="b">
<li>BAN SYSTEM</li>
<br>
<li>KICK SYSTEM</li>
<br>
<li>ADMIN JAIL SYSTEM</li>
<br>
</ul>
</div>
<div class="ban2">
<ul class="b">
<li>SEARCH SYSTEM</li>
<br>
<li>LOG SYSTEM</li>
<br>
<li>AWARD SYSTEM</li>
<br>
</ul>
</div>
<div class="ban3">
<ul class="b">
<li>MANAGAMENT SYSTEM</li>
<br>
<li>UNBAN SYSTEM</li>
<br>
<li>UNJAIL SYSTEM</li>
<br>
</ul>
</div>
<?php } ?>
You can make use of SESSION variables in php. You can check for that value and put a if statement.
Where Admin will be one of the attributes for user in your user table.
If truthy show your html section.
if (isset($_SESSION['Admin'])) {
// show your content
}
Checking for Admin level:
if ($_SESSION['Admin'] >= 1) {
// show your content
}
You can use if else in html like so
<?php if ($Admin === 1) : ?>
<h1> show admin html </h1>
<?php else if ($Admin < 1) : ?>
<h1> do smth else </h1>
<?php else : ?>
<h1> do thmth else </h1>
<?php endif : ?>
In your html file, you can write down like this ,
<?php if ( $admin>=1 ): ?>
<div>
Here you can put all of your html
code for admin.
</div>
<?php endif;?>
A Lot of imporoments have to be done for the coding. Follow following steps.
Create a PHP file ex:index.php
Add all your HTML code within that PHP file.
Write following code for display this section.
Procedure 1.
<?php
if($Admin > 1) {
?>
//write your html code here.
<?php
}
?>

Display slide with two records at a time

I want to display slide with two records at a time. Now I am only getting only one record at a time in slider because I fetch data in while loop. My code is:
<ul class="slides">
<?php
...
while($eventData = mysql_fetch_array($eventSql))
{
?>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<?php } ?>
</ul>
You can add a counter and open/close the list item only every second iteration:
<ul class="slides">
<li class="questions-slide-item">
<?php
...
$count = 0;
while($eventData = mysql_fetch_array($eventSql))
{
if($count > 0 && $count % 2 == 0) {
?>
</li>
<li class="questions-slide-item">
<?php
}
?>
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
<?php
$count++;
}
?>
</li>
</ul>
You can first take all the rows in one array and then use that array as per your needs.
See to following code to understand what I am trying to say.
<?php
...
$eventData= array();
while($row = mysql_fetch_assoc($eventSql))
{
$eventData [] = $row;
}
for($i=0;count($eventData);$i=$i+2)
{
?>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData[$i]['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData[$i+1]['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<?php } ?>

Is it possible to automatically insert the same image to every third slide

I'm using custom fields and would like to add an image to every third slide.. How do you do this.. could it possibly be done with jQuery and how?? So new to this
<div class="flexslider">
<ul class="slides slide-ul">
<?php while(the_repeater_field('text_scroll')): ?>
<li class="slide">
<span class="scroll-text1 slider"><?php the_sub_field('scroll_top_text');?></span>
<span class="scroll-text2 slider"><?php the_sub_field('scroll_bottom_text');?></span>
</li>
<?php endwhile; ?>
</ul>
</div>
Use nth child selector
DEMO
$('.slide:nth-child(3n)').append('<img src="IMage.jpg" />');
Using normal PHP
<div class="flexslider">
<ul class="slides slide-ul">
<?php $i=0 ; while(the_repeater_field( 'text_scroll')):
if($i % 3===0 ){echo '<li>each 3rd row this row will display</li>';} ?>
<li class="slide">
<span class="scroll-text1 slider">
<?php the_sub_field('scroll_top_text');?>
</span>
<span class="scroll-text2 slider">
<?php the_sub_field('scroll_bottom_text');?>
</span>
</li>
<?php $i++; endwhile; ?>
</ul>
</div>

Php Class Auto Increment

I want to generate the following code automatically within a Wordpress loop:
<ul class="content">
<li class="box it" data-id="id-1" data-type="it">
<h1>No# 01</h1>
</li>
<li class="box medical" data-id="id-2" data-type="medical">
<h1>No# 02</h1>
</li>
<li class="box education" data-id="id-3" data-type="education">
<h1>No# 03</h1>
</li>
</ul>
What I want it to have my php code from within the Wordpress loop to echo "data-id="+(auto incremented number as in the above instance).
How will I construct the loop?
try
<ul class="content">
<?php for($i=1;$i<some_num;$i++) {?>
<li class="box it" data-id="id-<?php echo $i; ?>" data-type="it">
<h1>No# <?php echo $i; ?></h1>
</li>
<?php } ?>
</ul>

Categories