Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This is my code. It is actually an html file. I want to loop those statements using php so that I can have that paragraph in my html page repeated for any number of times. Please help
<?php
for($i=0;$i<=5;$i++){
<li>
<div class="imgholder"><img src="images/demo/imgl.gif" alt="" /></div>
<div class="latestnews">
<h2>Text !</h2>
<p>Text 2</p>
</div>
<br class="clear" />
</li>
}
?>
You need to echo the HTML inside php:
<?php
for($i=0;$i<=5;$i++)
{
echo '<li>
<div class="imgholder"><img src="images/demo/imgl.gif" alt="" /></div>
<div class="latestnews">
<h2>Text !</h2>
<p>Text 2</p>
</div>
<br class="clear" />
</li>';
}
?>
Or you could just separate the HTML and php like:
<?php
for($i=0;$i<=5;$i++)
{ ?>
<li>
<div class="imgholder"><img src="images/demo/imgl.gif" alt="" /></div>
<div class="latestnews">
<h2>Text !</h2>
<p>Text 2</p>
</div>
<br class="clear" />
</li>
<?php } ?>
Close Php tag after braces, you can also write HTML in single Quotes.
<?php
for($i=0;$i<=5;$i++)
{
?>
<li>
<div class="imgholder"><img src="images/demo/imgl.gif" alt="" /></div>
<div class="latestnews">
<h2>Text !</h2>
<p>Text 2</p>
</div>
<br class="clear" />
</li>
<?php
}
?>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Here i am generating dynamic div i want to execute div first and second alternatively in PHP as dynamic values comes.. please help me related this.
here $count=$content_faq['number'];count of the result
<?php
foreach($content_faq['rows'] as $howit){
$count=$content_faq['number'];
$title=$howit->title;
$images=$howit->image;
$description=$howit->description;
for($i=0; $i < $count;$i++)
{
if($i % 2){ //remove quotes around 0
?>
<!-- div first -->
<div id="<?php echo rtrim($title); ?>" style="height: 400px; margin-top: 40px;">
<section >
<div class="container about-intro" >
<div class="col-lg-6">
<div class="image1_work">
<img class="img" height="380px" width="100%" src="<?=SITE_MEDIA?>images/howitwork/<?php echo $images?>" alt="image" >
</div>
</div>
<div class="col-lg-6">
<div class="" data-aos="fade-up">
<?php echo $description; ?>
</div>
</div>
</div>
</section><!-- closing of section is misplaced -->
</div>
<?php } else {?>
<!-- div Second -->
<div id="<?php echo rtrim($title); ?>" style="height: 400px; margin-top: 40px;">
<section >
<div class="container about-intro" >
<div class="col-lg-6">
<div class="" data-aos="fade-up">
<?php echo $description; ?>
</div>
</div>
<div class="col-lg-6">
<div class="image1_work">
<img class="img" height="380px" width="100%" src="<?=SITE_MEDIA?>images/howitwork/<?php echo $images?>" alt="image" >
</div>
</div>
</div>
</section>
</div>
<?php } } } ?>
My if and else condition not working in that case whats wrong there can anyone please help related this..
I want if id =1 then if part div execute, if id=2 cos its divisible and reminder is 0 then else part to be executed.. but i am not getting the same result what i am doing wrong here.
A job for the wonderful modulus operator!
Grab the array id with your foreach loop:
foreach ($content_faq['rows'] as $id=>$howit) {
And then use the modulus to alternate
if ($id % 2)
This will evaluate to 0 and 1 alternately, which we know are false and true.
Here's my HTML and PHP code but videos shown in vertical line, i use inline-block in CSS code but it doesn't work.
Please help me i am new to this.
HTML Code:
<div class="wrap">
<div class="grid">
<div class="preview">
<a title="<?php echo $video_title; ?>
"href="watch.php?videoid=<?php echo $video_id;?>">
<img src="videos/thumbnails/<?php echo $thumbnail;?> " />
</a>
<div class="time">00.00</div>
</div>
<div class="data">
<h3><a href="watch.php?videoid=<?php echo $video_id;?>">
<?php echo substr( $video_title,0,19);?>
<?php echo substr( $video_title,19,20);?>
</a>
</h3>
<div class="video-watch">
Watch Now
</div>
<div class="clear"> </div>
<div class="lables">
<p>Uploaded by:<a <?php if (isset($_SESSION['usr_name']))?>>
<?php echo $_SESSION['usr_name'] ;?>
</a>
</p>
</div>
<?php } }?>
</div>
</div>
Use an IFrame.
Here's an example of what it looks like:
<iframe width="420" height="315" src="https://www.youtube.com/embed/XGSy3_Czz8k">
this code shows a set of html statements embedded in a php file. Here in the second line i want that reference (href) value to be a variable depending upon the loop value ($i). But when I click on the link it goes to $i.html instead of going to the value in $i. please help
echo '<li>
<div class="imgholder">
<a href= "$i.html">
<img src="images/demo/imgl.png" alt="" />
</a>
</div>
<div class="latestnews">
<h2>Text 1</h2>
<p>Text 2</p>
</div>
<br class="clear" />
</li>';
There is concatenation operator ('.'), which returns the concatenation of its right and left arguments. Try with .:
echo '<li>
<div class="imgholder"><a href= "'. $i .'.html">
<img src="images/demo/imgl.png" alt="" /></a></div>
<div class="latestnews">
<h2>Text 1</h2>
<p>Text 2</p>
</div>
<br class="clear" />
</li>';
Try with
echo '<li>
<div class="imgholder"><a href= "'.$i.'.html">
<img src="images/demo/imgl.png" alt="" /></a></div>
<div class="latestnews">
<h2>Text 1</h2>
<p>Text 2</p>
</div>
<br class="clear" />
</li>';
You have to concatenate the PHP variable with the HTML tags. You got href as $i.html as the value of the variable was not substituted correctly.
How about you make it like this:
<?php for($i = 0; $i<10; $i++){ ?>
<li>
<div class="imgholder">
<img src="images/demo/imgl.png" alt="" />
</div>
<div class="latestnews">
<h2>Text 1</h2>
<p>Text 2</p>
</div> <br class="clear" />
</li>
<?php } ?>
In this context you have $i is a static String. But you want to have a variable which is dynamically changing.
Edited: Something like this is what I used to do, but it is not "clean" php.
Try this
echo "<li>
<div class='imgholder'><a href= '$i.html'>
<img src='images/demo/imgl.png' /></a></div>
<div class='latestnews'>
<h2>Text 1</h2>
<p>Text 2</p>
</div>
<br class='clear' />
</li>"
use double quotes or concatenation, as mentioned before.
But I'd like to recomend you to take a look on templates
like smarty or twig, or even plain php
I need to wrap my blog content into a div some how with jQuery. But images and divs and tables should be left out.
This markup:
<div class="entry-content">
<h1>Title</h1>
<div class="into">Some text is here</div>
<p>Paragraph text</p>
<p>Paragraph text</p>
<ul>
<li>Maybe list too</li>
<li>Like this</li>
</ul>
<div class="media">
<img src="" alt="" />
</div>
<p>Paragraph text</p>
<h2>Another title</h2>
<p>Paragraph text</p>
<h3>Yet another title</h3>
<p>Paragraph text</p>
<p>Paragraph text</p>
<blocquote>
<p>Quote</p>
</blockquote>
<h1>Second title</h1>
<h2>Sub Title</h2>
<p>Paragraph text</p>
<im src="" alt="" />
<p>Paragraph text</p>
<table>
<td></td>
</table>
<p>Paragraph text</p>
<h2>Title</h2>
<div class="media">
<img src="" alt="" />
</div>
<p>Paragraph text</p>
</div>
Into this:
<div class="entry-content">
<div class="container">
<h1>Title</h1>
<div class="into">Some text is here</div>
<p>Paragraph text</p>
<p>Paragraph text</p>
<ul>
<li>Maybe list too</li>
<li>Like this</li>
</ul>
</div>
<div class="media">
<img src="" alt="" />
</div>
<div class="container">
<p>Paragraph text</p>
<h2>Another title</h2>
<p>Paragraph text</p>
<h3>Yet another title</h3>
<p>Paragraph text</p>
<p>Paragraph text</p>
<blocquote>
<p>Quote</p>
</blockquote>
<h1>Second title</h1>
<h2>Sub Title</h2>
<p>Paragraph text</p>
</div>
<img src="" alt="" />
<div class="container">
<p>Paragraph text</p>
</div>
<table>
<td></td>
</table>
<div class="container">
<p>Paragraph text</p>
<h2>Title</h2>
</div>
<div class="media">
<img src="" alt="" />
</div>
<div class="container">
<p>Paragraph text</p>
</div>
</div>
So basically wrap everything to except img, .media and tables. This is done because text is going to be 660px wide when tables and images will be full browser width.
I'm using Drupal and this is content from wysiwyg so if someone knows how to do it on php level would be great but I believe this should be doable in jQuery too. Maybe with some regex?
Any help would be appreciated because I'm kind of lost.
You can do something like
var $els = $();
$('.entry-content').children().each(function(){
if($(this).is('img, .media')){
$els.wrapAll('<div class="container" />');
$els = $();
}else {
$els = $els.add(this);
}
});
$els.wrapAll('<div class="container" />');
Demo: Fiddle
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Okay so what I am after for here is to check if a checkbox has been ticked, if it has, then I would like to add the text into a <ul> class named, let's say, "confirmed", so <ul class="confirmed">,
If it hasn't been checked, then I would add the text to a <ul> class named "unconfirmed". Now I have the php code that checks if the checkbox has been confirmed (seen below), but I don't know what to add inside the statements. This is where I need help/guidance.
PHP IF code (Check if checkbox is ticked):
<?php
if (isset($_POST["checkbox1"])){
//write to <ul> class confirmed
} else {
//write to <ul> class unconfirmed
}
?>
Here's my HTML Code:
<body>
<div id="content">
<div class="jumbotron">
<h1>Is there football on Wednesday?</h1>
<h2>Yes.</h2>
</div>
<div class="alert alert-info" role="alert">Confirmed Players</div>
<ul class="list-group">
<li class="list-group-item">
<!--this is where to result of the php code would go if the checkbox is checked-->
Lorem Ipsor
</li>
</ul>
<div class="alert alert-danger" role="alert">Unconfirmed Players</div>
<li class="list-group-item">
<!--this is where to result of the php code would go if the checkbox is not checked-->
Lorem Ipsor
</li>
</div>
<!--form-->
<form action="check.php" method="POST">
<input type="checkbox" name="checkbox1">
<input type="submit"></input>
</form>
</body>
Sorry if I seem to be confusing you, as I said, I'm not too well. Any help/guidance would be great!
Alright so when you tick a checkbox it should return a value through the $_POST which is 1 or 0 on submit. You may modify your template like this:
<?php
if ($_POST['checkbox1']) {
$class = 'confirmed';
}
else {
$class = 'unconfirmed';
}
?>
<body>
<div id="content">
<div class="jumbotron">
<h1>Is there football on Wednesday?</h1>
<h2>Yes.</h2>
</div>
<div class="alert alert-info" role="alert">Confirmed Players</div>
<ul class="list-group <?php echo $class; ?>">
<li class="list-group-item">
Lorem Ipsor
</li>
</ul>
<div class="alert alert-danger" role="alert">Unconfirmed Players</div>
</div>
<!--form-->
<form action="check.php" method="POST">
<input type="checkbox" name="checkbox1" />
<input type="submit" />
</form>
</body>
To be sure you can always var_dump the $_POST to see what is coming through in it and modify your if statement to be more accurate, it should return 1 or 0 iirc.
Without using AJAX you can try nesting php code like this:
<ul class="list-group">
<li class="list-group-item">
<?php
if (isset($_POST["checkbox1"])){
//write to <ul> class confirmed
}
?>
</li>
</ul>
<div class="alert alert-danger" role="alert">Unconfirmed Players</div>
<li class="list-group-item">
<?php
if (!isset($_POST["checkbox1"])){
//write to <ul> class unconfirmed
}
?>
</li>