How do i echo a chunk of html with php - php

Basically what I want to do is this...
If column (seperate_sitting_yes) in row ($rows1) in table = 'yes' echo this chunk of html. Else echo this other chunk of hmtl (I have used an echo statement "nothing" for ease.
if ($rows1['seperate_sitting_yes'] == "No";){
echo
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_monday_from']; echo $rows1['opening_monday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Tuesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_tuesday_from']; echo $rows1['opening_tuesday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Wednesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_wednesday_from']; echo $rows1['opening_wednesday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Thursday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_thursday_from']; echo $rows1['opening_thursday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Friday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_friday_from']; echo $rows1['opening_friday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Saturday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_saturday_from']; echo $rows1['opening_saturday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Sunday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_sunday_from']; echo $rows1['opening_monday_to'];/p></div>;
}
else {echo "nothing";}
But i'm not sure how to address this correctly. Can anyone shed any light on the matter. Please and thank you.

Here is your answer bellow. Basically you need to echo the entire html as a string via php. So you have to put the entire code in a '' quotes and plus you are attaching php variables in it so you can concatinate it via '.'
if ($rows1['seperate_sitting_yes'] == "No")
{
echo '<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_monday_from'].''.$rows1['opening_monday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_tuesday_from'].''.$rows1['opening_tuesday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_wednesday_from'].''.$rows1['opening_wednesday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_thursday_from'].''.$rows1['opening_thursday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_friday_from'].''.$rows1['opening_firday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_saturday_from'].''.$rows1['opening_saturday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_sunday_from'].''.$rows1['opening_sunday_to'];'</p></div>
</div>';
}
else {echo "nothing";}

Try letting HTML do most of the heavy lifting and insert PHP echos where needed.
<?php if ($rows1['seperate_sitting_yes'] == "No";){ ?> //Close off PHP here
<!-- This is all HTML here -->
<!-- Below is HTML code injected with PHP variable -->
<div><?php echo $variableThatNeedsToBeInserted ?></div>
<?php }else {echo "nothing";} ?> //Closing PHP tag for end } bracket, and else case.
Hope this gives you an idea!

In your first line there is an ";" that doesn't need to be there...
Instead of
if ($rows1['seperate_sitting_yes'] == "No";){
Try
if ($rows1['seperate_sitting_yes'] == "No"){
The ";" denotes the end of a line of code in PHP. When you are trying to evaluate something in an if statement, that is not the end of the line. So remove it, and be sure that $rows1['seperate_sitting_yes'] is producing expected results.
And as said in other comments, seperate out the PHP and the HTML see the modified code below
<?php
$rows1['seperate_sitting_yes'] = "No";
if ($rows1['seperate_sitting_yes'] == "No"){
?>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_monday_from']; echo $rows1['opening_monday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Tuesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_tuesday_from']; echo $rows1['opening_tuesday_to'];?><p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Wednesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_wednesday_from']; echo $rows1['opening_wednesday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Thursday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_thursday_from']; echo $rows1['opening_thursday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Friday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_friday_from']; echo $rows1['opening_friday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Saturday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_saturday_from']; echo $rows1['opening_saturday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Sunday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_sunday_from']; echo $rows1['opening_monday_to'];?></p></div>;
<?php }
else {echo "nothing";}
?>

Related

How to display a particular div in jquery?

I have written some code for displaying a particular div in html. The code is shown below :
<div id="pdfdiv_1">
<section class="report">
<div class="top-box"></div>
<div class="row">
<div class="col-md-12 text-center">
<img src="<?php echo base_url()?>reports-assets-new/images/banner.png" class="bannerimg" style="
width: auto;">
</div>
<div class="col-md-5">
<div class="info-wrapper">
<?php if(!empty($user_details->st_profile)){ ?>
<img src="<?php echo base_url();?>uploads/user-profile/<?php echo $user_details->st_profile;?>" style="width: 22%;">
<?php } else {?>
<img src="<?php echo base_url()?>reports-assets-new/images/img2.png">
<?php } ?>
<div class="info-wrap-inner">
<p><span>Name </span> : <?php echo $user_details->st_name;?></p>
<p><span>Age </span> : <?php echo $age;?></p>
<p><span>Education </span> : <?php echo $user_details->st_qualification;?></p>
<p><span>Mobile </span> : <?php echo $user_details->st_mobile;?></p>
<p><span>Email </span> : <?php echo $user_details->st_email;?></p>
<p><span>Date of test </span> : <?php $s=$user_details->c_date; $dt = new DateTime($s); $date = $dt->format('d-m-Y'); echo $date; ?></p>
</div>
</div>
</div>
<div class="col-md-7 report-wrapper">
<h1 class="heading">SKILL FINDER TEST REPORT</h1>
<p><?php echo $test_details->description;?></p>
</div>
</div>
</div>
</section>
<section class="skills">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><span>IDENTIFY SKILLS BASED ON YOUR INTERESTS</span></h1>
</div>
</div>
<div class="row">
<?php echo $test_details->description3;?>
</div>
</section>
</div><!-- pdfdiv close -->
I have written a code for displaying the div pdfdiv_1 in jquery as shown below :
<script>
function pdfP(exam_id,test_id,base_url) {
var test = document.getElementById('pdfdiv_1').innerHTML;
console.log(test);
$.ajax({
type: 'POST',
data: {test : test,exam_id:exam_id,test_id:test_id},
url: base_url+"reports/reports_pdf_new/skill_finder",
success: function (data) {
window.location.href = base_url+"reports_pdf_new/"+exam_id+"/"+test_id;
},
});
}
</script>
When I am printing the console output, it is only printing the first section part but not the second section tag.
The output in console is :
<section class="report">
<div class="top-box"></div>
<div class="row">
<div class="col-md-12 text-center">
<img src="<?php echo base_url()?>reports-assets-new/images/banner.png" class="bannerimg" style="
width: auto;">
</div>
<div class="col-md-5">
<div class="info-wrapper">
<?php if(!empty($user_details->st_profile)){ ?>
<img src="<?php echo base_url();?>uploads/user-profile/<?php echo $user_details->st_profile;?>" style="width: 22%;">
<?php } else {?>
<img src="<?php echo base_url()?>reports-assets-new/images/img2.png">
<?php } ?>
<div class="info-wrap-inner">
<p><span>Name </span> : <?php echo $user_details->st_name;?></p>
<p><span>Age </span> : <?php echo $age;?></p>
<p><span>Education </span> : <?php echo $user_details->st_qualification;?></p>
<p><span>Mobile </span> : <?php echo $user_details->st_mobile;?></p>
<p><span>Email </span> : <?php echo $user_details->st_email;?></p>
<p><span>Date of test </span> : <?php $s=$user_details->c_date; $dt = new DateTime($s); $date = $dt->format('d-m-Y'); echo $date; ?></p>
</div>
</div>
</div>
<div class="col-md-7 report-wrapper">
<h1 class="heading">SKILL FINDER TEST REPORT</h1>
<p><?php echo $test_details->description;?></p>
</div>
</div>
</div>
</section>
Can anyone help me out in this ?
I cant print all the html code present inside the div pdfdiv_1.
The html code :
<div class="download-pdf">
<div class="row">
<div class="col-12">
<div class="card p-4 mt-0">
<h2 class="text-center mb-0">Congratulations!</h2>
<p class="lead text-center" style="margin-top: -18px">
<br>
<div class="button-wrapper" style="text-align: center;">
<button onclick="pdfP(<?php echo $exam_id;?>,<?php echo $test_id;?>,'<?php echo base_url();?>')" class="btn btn-primary d-block mx-auto">Download PDF</button>
<span id="pdfloader"></span>
</div>
</div>
</div>
</div>
</div>
There are some mistakes on html tags placement.
This code might fix them :
<div id="pdfdiv_1">
<section class="report">
<div class="top-box"></div>
<div class="row">
<div class="col-md-12 text-center">
<img src="<?php echo base_url()?>reports-assets-new/images/banner.png" class="bannerimg" style="
width: auto;">
</div>
<div class="col-md-5">
<div class="info-wrapper">
<?php if(!empty($user_details->st_profile)){ ?>
<img src="<?php echo base_url();?>uploads/user-profile/<?php echo $user_details->st_profile;?>" style="width: 22%;">
<?php } else {?>
<img src="<?php echo base_url()?>reports-assets-new/images/img2.png">
<?php } ?>
<div class="info-wrap-inner">
<p><span>Name </span> : <?php echo $user_details->st_name;?></p>
<p><span>Age </span> : <?php echo $age;?></p>
<p><span>Education </span> : <?php echo $user_details->st_qualification;?></p>
<p><span>Mobile </span> : <?php echo $user_details->st_mobile;?></p>
<p><span>Email </span> : <?php echo $user_details->st_email;?></p>
<p><span>Date of test </span> : <?php $s=$user_details->c_date; $dt = new DateTime($s); $date = $dt->format('d-m-Y'); echo $date; ?></p>
</div>
</div>
</div>
<div class="col-md-7 report-wrapper">
<h1 class="heading">SKILL FINDER TEST REPORT</h1>
<p><?php echo $test_details->description;?></p>
</div>
</div>
</section>
<section class="skills">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><span>IDENTIFY SKILLS BASED ON YOUR INTERESTS</span></h1>
</div>
</div>
<div class="row">
<?php echo $test_details->description3;?>
</div>
</div>
</section>
</div><!-- pdfdiv close -->
Generally the IDE show these errors in red.
Example with IntelliJ softwares :

Column Bootstrap in while loop PHP

I have this problem
and that code is here
<div class="col-md-4 text-center animate-box">
<a href="work-single.html" class="work" style="background-image: url(images/portfolio-2.jpg);">
<div class="desc">
<h3>Project Name</h3>
<span>Brading</span>
</div>
</a>
</div>
<div class="col-md-4 text-center animate-box">
<a href="work-single.html" class="work" style="background-image: url(images/portfolio-2.jpg);">
<div class="desc">
<h3>Project Name</h3>
<span>Brading</span>
</div>
</a>
</div>
<div class="col-md-4 text-center animate-box">
<a href="work-single.html" class="work" style="background-image: url(images/portfolio-2.jpg);">
<div class="desc">
<h3>Project Name</h3>
<span>Brading</span>
</div>
</a>
</div>
now i tried to do a while loop for my php and did this code
<div class="row">
<?php
while ($userRow=$stmt2->fetch(PDO::FETCH_ASSOC))
{
echo "<div class='col-md-4 text-center animate-box'>";
echo "<a href='work-single.html' class='work' style='background-image:url(uploaded_files/uploaded_files_articles_images/" .$userRow['image']. ")';";
echo "<div class='desc'>";
echo "<h3>Project Name</h3>";
echo "<span>Illustration</span>";
echo "</div>";
echo "</a>";
echo"</div>";
}
?>
</div>
and it got me this
So what i tried so far is this
<?php
while ($userRow=$stmt2->fetch(PDO::FETCH_ASSOC))
{
<?
<div class='col-md-4 text-center animate-box'>
<?php
echo "<a href='work-single.html' class='work' style='background-image:url(uploaded_files/uploaded_files_articles_images/" .$userRow['image']. ")';";
echo "<div class='desc'>";
echo "<h3>Project Name</h3>";
echo "<span>Illustration</span>";
echo "</div>";
echo "</a>";
<?
</div>
<?php
}
?>
but still not working still the same layout . sorry for my bad english . Can someone help me to figure out what is the problem on my code. Thank you everyone in advance
echo "<a href='work-single.html' class='work' style='background-image:url(uploaded_files/uploaded_files_articles_images/" .$userRow['image']. ")';";
You are missing a > at the end.
You've missed a > in your anchor tag and also misplaced the semicolon of the CSS. Replace your code with the following one.
echo "<a href='work-single.html' class='work' style='background-image:url(uploaded_files/uploaded_files_articles_images/" .$userRow['image']. ");'>";

Edit option from Radio Buttons in PHP

I am VERY new to PHP and editing some code
Currently it has two radio buttons. Selecting either will bring up some options.
I am wanting to get rid of one option (pick up) and have the page just show the delivery option.
Any help would be ace, I have tried playing with the code but no luck!
<div class="top10 row">
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>'pickup',
'required'=>true
));
?>
<span><?php echo Driver::t("Pickup")?></span>
</div>
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>"delivery"
));
?>
<span><?php echo Driver::t("Delivery")?></span>
</div> <!--col-->
</div> <!--row-->
<div class="delivery-info top20">
<div class="row">
<div class="col-sm-6">
<?php echo CHtml::textField('contact_number','',array(
'class'=>"mobile_inputs",
'placeholder'=>Driver::t("Contact nunber"),
'maxlength'=>15
))?>
</div> <!--col-->
<div class="col-sm-6 ">
<?php
echo CHtml::textField('email_address','',array(
'placeholder'=>Driver::t("Email address")
))
?>
</div> <!--col-->
</div> <!--row-->
<div class="row top10">
<div class="col-sm-6 ">
<?php echo CHtml::textField('customer_name','',array(
'placeholder'=>Driver::t("Name"),
'required'=>true
))?>
</div>
<div class="col-sm-6 "><?php echo CHtml::textField('delivery_date','',array(
'placeholder'=>Driver::t("Delivery before"),
'required'=>true,
'class'=>"datetimepicker"
))?></div>
</div> <!--row-->
<div class="row top10">
<div class="col-sm-12 ">
<?php
$map_provider = Driver::getMapProvider();
?>
<?php if ($map_provider =="mapbox"):?>
<div id="mapbox_delivery_address" class="mapbox_geocoder_wrap"></div>
<?php elseif ( $map_provider=="google.maps"):?>
<?php
echo CHtml::textField('delivery_address','',array(
'class'=>'delivery_address geocomplete delivery_address_task',
'placeholder'=>Driver::t("Delivery Address"),
'required'=>true
));
?>
<?php endif;?>
Remove the lines of code below (or comment them out while you try it). Make a copy of the file before you make any changes in case you need to back out the attempt.
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>'pickup',
'required'=>true
));
?>
<span><?php echo Driver::t("Pickup")?></span>
</div>

how can i call datas in a row on html from database

i call datas from database but there are not in a row.
how can i do that.
codes;
<?php
$test=mysql_query("SELECT * FROM siteler");
$sayi=mysql_num_rows($test);
$deneme=mysql_fetch_row($test);
while ($deneme=mysql_fetch_assoc($test)) {
extract($deneme);
echo "<div class='container'>
<div class='row'>
<div class='col-md-3 col-sm-6 col-xs-12 back-colour'>
<p>$site_name </p>
<p>$site_info </p>
<p>$site_ref </p>
<p>$bet_turu </p>
</div>
</div>
</div>";}
?>
thats what happened
http://imgur.com/a/Hg2W6
thats what i want
http://imgur.com/CpE8RB8
Try this,
<?php
$test=mysql_query("SELECT * FROM siteler");
$sayi=mysql_num_rows($test);
$deneme=mysql_fetch_row($test);
?>
<div class='container'>
<div class='row'>
<?php
while ($deneme=mysql_fetch_assoc($test)) {
extract($deneme);
echo "<div class='col-md-3 col-sm-6 col-xs-12 back-colour'>
<p>$site_name </p>
<p>$site_info </p>
<p>$site_ref </p>
<p>$bet_turu </p>
</div>";
}
?>
</div>
</div>
Hope this will fix the issue

If/else statement inside the same div tag (formatting)

I'm trying to get the formatting of php and html in the same document right. I can't seem to get the conversion right.
....
This is the original HTML:
<div class="content-holder clearfix">
<div class="container">
<div class="row">
<div class="span12">
<div class="row">
<div id="title-header" class="span12">
<div class="page-header">
<?php get_template_part("static/static-title"); ?>
</div>
</div>
<div class="row">
<?php if ($masonrycategory=='false') { ?>
<div class="span8 <?php if (of_get_option('blog_sidebar_pos')==''){echo 'right';}else{echo of_get_option('blog_sidebar_pos'); } ?>" id="content">
<?php get_template_part("loop/loop-blog-main"); ?>
</div>
<div class="span4 sidebar" id="sidebar">
<?php dynamic_sidebar("hs_main_sidebar"); ?>
</div>
<?php }else{ ?>
<div class="span12 id="content">
<?php get_template_part("loop/loop-blog-masonry"); ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
And I need to convert it to PHP.
...
} else {
echo "<div class='content-holder clearfix'>";
echo "<div class='container'>";
echo "<div class='row'>";
echo "<div class='span12'>";
echo "<div class='row'>";
echo "<div id='title-header' class='span12'>";
echo "<div class='page-header'>";
get_template_part("static/static-title");
echo "</div>";
echo "</div>";
echo "<div class='row'>"
if ($masonrycategory=='false') {
echo "<div class='span8' . 'if (of_get_option('blog_sidebar_pos')==''){echo 'right';}else{echo of_get_option('blog_sidebar_pos'); } ?>" id="content">
<?php get_template_part("loop/loop-blog-main"); ?>
</div>
<div class="span4 sidebar" id="sidebar">
<?php dynamic_sidebar("hs_main_sidebar"); ?>
</div>
<?php }else{ ?>
<div class="span12 id="content">
<?php get_template_part("loop/loop-blog-masonry"); ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
} ?>
Syntax error:
echo "<div class='span8' . 'if (of_get_option('blog_sidebar_pos')==''){echo 'right';}else{echo of_get_option('blog_sidebar_pos'); } ?>" id="content">
Until you are more confident, you might find it easier to be more vebose in your style of coding:
echo '<div class="span8';
if (of_get_option('blog_sidebar_pos') == '') {
echo ' right';
} else {
echo of_get_option('blog_sidebar_pos');
}
echo '" id="content">';
You can use the if else shorthand like this:
div class="span8 <?php $v= (of_get_option('blog_sidebar_pos')=='')? 'right':of_get_option('blog_sidebar_pos') ;echo $v;?>" id="content">
Considering of_get_option fn does't have any error.

Categories