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']. ");'>";
Related
This PHP code outputs HTML to the user.
<div class="whole">
<input type="hidden" class="hid" name="hid" value="<?php echo $datum['id']; ?>">
<div class="col1"> <div class="d1" id="naam<?php echo $datum['id']; ?>"><?php echo $datum['name']; ?></div>
</div>
<div class="col2"> <div class="d2" id="email<?php echo $datum['id']; ?>"><?php echo $datum['email']; ?></div>
</div>
<div class="col3"> <div class="d3" id="state<?php echo $datum['id']; ?>"><?php echo $datum['state']; ?></div>
</div>
<div class="col4"> <div class="d4" id="gender<?php echo $datum['id']; ?>"><?php echo $datum['gender']; ?></div>
</div>
<div class="col5"> <div class="d5" id="lang<?php echo $datum['id']; ?>"><?php echo $datum['lang']; ?></div>
</div>
<div class="col6">
<?php
echo "<a href='images/".$datum['image']."' data-lightbox='picbox' data-title='".$datum['image']."'> <img src='images/".$datum['image']."'></a>";
?>
</div>
</div>
Instead of sending this output to the user, I want it in the variable $output. How can I do this?
You can use Jquery to get HTML code inside your div:
$( document ).ready(function() {
data = $(".whole").html();
console.log(data);
});
Where data is:
<input type="hidden" class="hid" name="hid" value="<?php echo $datum['id']; ?>">
<div class="col1"> <div class="d1" id="naam<?php echo $datum['id']; ?>"><!--?php echo $datum['name']; ?--></div>
</div>
<div class="col2"> <div class="d2" id="email<?php echo $datum['id']; ?>"><!--?php echo $datum['email']; ?--></div>
</div>
<div class="col3"> <div class="d3" id="state<?php echo $datum['id']; ?>"><!--?php echo $datum['state']; ?--></div>
</div>
<div class="col4"> <div class="d4" id="gender<?php echo $datum['id']; ?>"><!--?php echo $datum['gender']; ?--></div>
</div>
<div class="col5"> <div class="d5" id="lang<?php echo $datum['id']; ?>"><!--?php echo $datum['lang']; ?--></div>
</div>
<div class="col6">
<!--?php
echo "<a href='images/".$datum['image']."' data-lightbox='picbox' data-title='".$datum['image']."'--> <img src="images/".$datum[" image']."'="">";
?>
After that you can send data to PHP via AJAX
<?php
ob_start();
?>
your html goes here
<?php
$html = ob_get_contents();
ob_end_clean();
Use heredoc syntax, like so:
$output = <<<ANY_IDENTIFIER_THAT_DOES_NOT_APPEAR_IN_THE_TEXT_HERE
<div class="whole">
<input type="hidden" class="hid" name="hid" value="{$datum['id']}">
<div class="col1"> <div class="d1" id="naam{$datum['id']}">{$datum['name']}</div>
</div>
<div class="col2"> <div class="d2" id="email{$datum['id']}">{$datum['email']}</div>
</div>
<div class="col3"> <div class="d3" id="state{$datum['id']}">{$datum['state']}</div>
</div>
<div class="col4"> <div class="d4" id="gender{$datum['id']}">{$datum['gender']}</div>
</div>
<div class="col5"> <div class="d5" id="lang{$datum['id']}">{$datum['lang']}</div>
</div>
<div class="col6">
<a href='images/{$datum['image']}' data-lightbox='picbox' data-title='{$datum['image']}'> <img src='images/{$datum['image']}'></a>
</div>
</div>
ANY_IDENTIFIER_THAT_DOES_NOT_APPEAR_IN_THE_TEXT_HERE;
This last part must be exactly the same identifier as at the beginning, unindented and followed by a semicolon.
Also, note that I took out all of the <?php ?> sections, and replaced them with {$datum['image']} accesses (unless I missed one). Heredocs in PHP work just like "double quoted strings", except spread across multiple lines and able to include " marks.
For more information, see the PHP documentation on string syntax.
I'm trying to make a responsive php/mysql image system.
I took this Code from the internet:
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="item-container">
<a href="#">
<div class="item-caption">
<div class="item-caption-inner">
<div class="item-caption-inner1">
<h3>$45</h3>
<span>Only</span>
</div>
</div>
</div>
<img src="images/menu-1.jpg" />
</a>
</div>
<div class="item-container">
<a href="#">
<div class="item-caption">
<div class="item-caption-inner">
<div class="item-caption-inner1">
<h3>$45</h3>
<span>Only</span>
</div>
</div>
</div>
<img src="images/menu-5.jpg" />
</a>
</div>
</div>
</div>
Which is showing this: img
and tried to make it responsive with mysql and php. So I can add the images.
<div class="row">
<?php
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc()) {
if($row['Ordine'] %2 != 0)
{
echo "<div class='col-lg-3 col-md-3 col-sm-6 col-xs-12'>";
}
echo "
<div class='item-container'>
<a href='#'>
<div class='item-caption'>
<div class='item-caption-inner'>
<div class='item-caption-inner1'>
<h3>$45</h3>
<span>Only</span>
</div>
</div>
</div>
<img src='/dulcearoma/admin/images/" . $row["Poza"]. "' />
</a>
</div>";
if($row['Ordine'] %2 != 0)
{
echo "</div>";
}
}
}
?>
</div>
but it's looking like this: enter image description here
The Ordine row is 1,2,3,4,5,6 etc.
Any ideas what I did wrong?
I'm really out of ideas
please use boostrap class="img-responsive" and add height and width in img tag
example :
<img src="images/menu-5.jpg" class="img-responsive" width="304" height="236">
I have this following snippet:
<?php
if($people->num_rows >= 1) {
while($person = $people->fetch_object()) {
echo '
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="card card-user">
<div class="content">
<div class="author">
<a href="'.$system->getDomain()?>/user/<?=$person->id.'">
<img class="avatar" src="'.$system->getProfilePicture($person).'">
<h4 class="title">'.$system->getFirstName($person->full_name).', '.$person->age.'</h4>
</a>
</div>
<p class="text-center text-muted">
';
echo $person->city.$system->ifComma($person->city); echo ' '.$person->country.'
</p>
</div>
</div>
</div>
';
}
} else {
?>
however next to the actual age (after the closing H4 tag) I'd like to add a further function which shows the current online status of the user.
The code for this would be as follows:
<?php if($system->isOnline($profile->last_active)) { echo '<i class="online-status online"></i>'; } else { echo '<i class="online-status offline"></i>'; } ?>
What is the best way to combine this snippet (online status) with the statement above?
Some expert help would be greatly appreciated
Separate your HTML and PHP code and do it like the below. Your requirement is done using a single line ternary operator.
<?php
if($people->num_rows >= 1) {
while($person = $people->fetch_object()) { ?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="card card-user">
<div class="content">
<div class="author">
<a href="<?php echo $system->getDomain().'/user/'.$person->id;?>">
<img class="avatar" src="<?php echo $system->getProfilePicture($person);?>">
<h4 class="title"><?php echo $system->getFirstName($person->full_name).', '.$person->age;?></h4>
<?php echo ($system->isOnline($profile->last_active)) ? '<i class="online-status online"></i>' : '<i class="online-status offline"></i>'; ?>
</a>
</div>
<p class="text-center text-muted">
<?php echo $person->city.$system->ifComma($person->city); echo ' '.$person->country;?>
</p>
</div>
</div>
</div>
<?php
}
}
?>
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.
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";}
?>