I am developing a simple project but encountered a problem which I can not find solution.
The follow php code:
<?php include "header.php"; ?>
<?php
$subtitle = "Os teus animes favoritos diariamente!";
$conn = mysqli_connect("$host","$dbuser","$dbpw","$db");
if (mysqli_connect_errno())
{
echo "Falha ao ligar à Base de Dados: " . mysqli_connect_error();
}
$result = mysqli_query($conn, "SELECT * FROM m_capitulos ORDER BY 'm_capitulos'.'id_cap' DESC LIMIT 30") or die(mysqli_error($conn));
mysqli_close($conn);
?>
<section class="mbr-section mbr-section--relative mbr-section--fixed-size mbr-after-navbar" id="features1-3" style="background-color: rgb(255, 255, 255);">
<div class="mbr-section__container container"><!-- "mbr-section__container--std-top-padding" para dar padding no top! -->
<div class="mbr-section__row row">
<?php while ($row = mysqli_fetch_array($result)){ ?>
<div class="mbr-section__col col-xs-12 col-sm-4">
<div class="mbr-section__container mbr-section__container--center mbr-section__container--middle">
<figure class="mbr-figure"><img class="mbr-figure__img" src="<?php echo $row['p_thumb']; ?>"></figure>
</div>
<div class="mbr-section__container mbr-section__container--middle">
<div class="mbr-header mbr-header--reduce mbr-header--center mbr-header--wysiwyg">
<h3 class="mbr-header__text"><?php echo $row['nombre_cap']; ?></h3>
</div>
</div>
<div class="mbr-section__container mbr-section__container--last">
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">ASSISTIR</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
<?php include "footer.php"; ?>
But when I remove the page css the empty space between the results disappears.
The Empty Space on the midle of my content box :
The result on the right just above the space is shorter, thus the next element goes below it instead of going to next row. I suggest you split elements into groups of 3 so that they can go into rows, or alternatively set the height for each result so that they all line up.
The example below adds a counter; every time you run through an element it checks if the element count divides by three, and if so, starts a new row. The same check is done at the end, except that it checks whether the element is the last in the row-of-three, and if so, ends the row tag.
<?php
$i = 0;
while ($row = mysqli_fetch_array($result)){ ?>
<?php if ($i % 3 == 0): ?><div class="row"><?php endif; ?>
<div class="mbr-section__col col-xs-12 col-sm-4">
<div class="mbr-section__container mbr-section__container--center mbr-section__container--middle">
<figure class="mbr-figure"><img class="mbr-figure__img" src="<?php echo $row['p_thumb']; ?>"></figure>
</div>
<div class="mbr-section__container mbr-section__container--middle">
<div class="mbr-header mbr-header--reduce mbr-header--center mbr-header--wysiwyg">
<h3 class="mbr-header__text"><?php echo $row['nombre_cap']; ?></h3>
</div>
</div>
<div class="mbr-section__container mbr-section__container--last">
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">ASSISTIR</div>
</div>
</div>
<?php if ($i % 3 == 2): ?></div><?php endif;
$i++
?>
<?php } ?>
Related
Trying to display the custom posts on my archive page within a bootstrap row containing 3 columns then starting a new row, got the code but new to PHP and dont know where to put the content.
<?php
//Columns must be a factor of 12 (1,2,3,4,6,12)
$numOfCols = 3;
$rowCount = 0;
$bootstrapColWidth = 12 / $numOfCols;
?>
<div class="row">
<?php
foreach ($rows as $row){
?>
<div class="col-md-4"<?php echo $bootstrapColWidth; ?>">
<div class="thumbnail">
<img src="user_file/<?php echo $row->foto; ?>">
</div>
</div>
<?php
$rowCount++;
if($rowCount % $numOfCols == 0) echo '</div><div class="row">';
}
?>
</div>
<div class="embed-container">
<?php the_field('podcast_embed_link'); ?>
</div>
<h3><?php the_title(); ?></h3>
<p><b><?php echo $date->format( $format_out );?></b></p>
<p><?php the_field('description'); ?></p>
<?php if( get_field('thumbnail') ): ?>
<img src="<?php the_field('thumbnail'); ?>" />
<?php endif; ?>
<?php endwhile; // end of the loop. ?>
</div>
</div>
</div><!-- #content -->
Here is the code for the page archive.podcasts.php, where would i add the custom fields within the row loop?
First of all, you don't need to close and open row tag each 3 items. If you leave the code like this:
<div class="row">
<?php
foreach ($rows as $row){
?>
<div class="col-md-<?php echo $bootstrapColWidth; ?>">
<div class="thumbnail">
<img src="user_file/<?php echo $row->foto; ?>">
</div>
</div>
<?php
}
?>
</div>
you will get the same effect, but without the separation that a row tag involves. Notice that the line involving "col-md-4" has already changes in order to not create wrong col size usage.
In this part of code:
<div class="col-md-4"<?php echo $bootstrapColWidth; ?>">
You must get wrong bootstrap class like col-md-41, col-md-412.
Correct you code by this way:
<div class="col-md-<?php echo $bootstrapColWidth; ?>">
<?php session_start();
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'])
{
header('Location: /admin');
}
include 'includes/header.inc'; ?>
<div class="main_content_wrapper">
<div class="main_content limit_main_content_width margin_center p20">
<div class="question_wrapper main_content_content homepage_section" style='margin-top: 20px'>
<div>Ask any cooking related doubts or learn from already answered quesetions.</div>
</div>
<div class="question_wrapper main_content_content homepage_section">
<div class='big_heading'>Ask your doubt</div>
<div class="question_wrapper_content question_div_wrapper mb10">
<div class="question_wrapper_content question_div_wrapper placeholder_text js_main_question_placeholder">Write your question here</div>
<div class='question_wrapper_content question_div_wrapper ask_question_box p20 subtle_border radius3 mb10 js_main_question_value js_main_question_input' contenteditable='true'></div>
<input type="email" class="p20 subtle_border question_wrapper_content email_input js_main_email_value" placeholder='Enter your email here'>
<div class="g-recaptcha mt10" data-sitekey="6LcIo9oSAAAAAPTdolZGu6RoMDybW0Q66-TLTkbV"></div>
</div>
<div class="everyOtherGreenButton inline_middle question_wrapper_content submit_main_question js_submit_main_question center_align">ASK ME NOW</div>
<div class="everyOtherGreenButton inline_middle question_wrapper_content sending_main_question js_sending_main_question center_align noafter">SENDING...</div>
<div class='inline_middle bold question_wrapper_content response_message question_sent_success js_question_sent_success'>Success! You will receive an email when Kavita answers the question. :D</div>
<div class='inline_middle bold question_wrapper_content response_message question_sent_error js_question_sent_error'>There was an unknown error :( Please try again or refresh the page.</div>
</div>
<div class="question_wrapper main_content_content homepage_section">
<div class='big_heading'>Recently answered questions</div>
<div class="recently_answered_wrapper">
<?php
include 'includes/database_login.inc';
$sql_query = "SELECT * FROM posts WHERE published = 1 and deleted = 0 and answered = 1 ORDER BY answered_on DESC LIMIT 5";
$result = mysqli_query($conn, $sql_query);
echo $result->num_rows;
$rowCount = '2';
echo $rowCount;
$p_index = 0;
while($row = mysqli_fetch_assoc($result)) {
?><a href='/post.php?id=<?php echo $row["id"]; ?>' class="recently_answered_wrapper_content recently_answered_question inline_middle subtle_border recent<?php echo $p_index%4; ?>">
<div class="title p10 bold">Q. <?php echo $row['title']; ?></div>
<div class="answer p10" style='padding-top: 0'><?php echo $row['answer']; ?></div>
</a><?php //$p_index++;
}
$conn->close(); ?><a href='/posts.php' class="recently_answered_wrapper_content recently_answered_question noborder view_all_answered_questions inline_middle center_align">
<div class="p10 bold" style="margin-top: 55px;">VIEW ALL ANSWERS</div>
</a>
</div>
</div>
</div>
This is a snippet of my php code. I have somehow figured that the error Unexpected end of file is happening here. But I don't see why.
UPDATE
When I comment out echo $rowCount, it doesnt show any errors.
I create two design to display news .
first DIV Display BIGGER images and Separate css class and display only two rows.
Second DIV Display Smaller images and Separate css class and display five rows..
I select rows in asc order from query.
my query is = select * from news order by priority asc.
My Only Need is TO Display two rows in First div and then display another rows in Second DIV.
IS This is possible using if else or any other condition...how to do this.........
but keep all div tag as it is bcoz of page design purpose......
<!-- FIRST DIV -->
<div class="post">
<div class="buffer">
<?php foreach($top2 as $top){ ?>
<div class="content"> <img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" style="width:285px; height:100px;" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
<!--<p class="details2">8 Comments / Read More</p>-->
</div>
</div>
<!-- end post -->
<!-- SECOND DIV -->
<!-- begin post -->
<div class="post">
<div class="buffer">
<?php foreach($top2 as $top){ ?>
<div class="content1"><img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
</div>
</div>
<!-- end post -->
Yes, it's possible. Assuming your $top2 array has standard numerical/sequential keys, then:
$split = 2;
for($i = 0; $i < $split; $i++) {
... print $top2[0] and $top2[1]
}
for ($i = $split; $i < count($top2); $i++) {
... print the rest of the rows
}
Can use array_slice()
<!-- FIRST DIV -->
<div class="post">
<div class="buffer">
<?php $arr = array_slice($top2, 0, 2) ?>
<?php foreach($arr as $top){ ?>
<div class="content"> <img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" style="width:285px; height:100px;" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
<!--<p class="details2">8 Comments / Read More </p>-->
</div>
</div>
<!-- end post -->
<!-- SECOND DIV -->
<!-- begin post -->
<div class="post">
<div class="buffer">
<?php $arr = array_slice($top2, 2) ?>
<?php foreach($arr as $top){ ?>
<div class="content1"><img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
</div>
Add a count that you increment in the foreach loop, then break when its over two:
<!-- FIRST DIV -->
<div class="post">
<div class="buffer">
<?php
$rowCount = 0;
foreach($top2 as $top){ ?>
<div class="content"> <img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" style="width:285px; height:100px;" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php
$rowCount++;
if($rowCount > 2){
break;
}
} ?>
<!--<p class="details2">8 Comments / Read More</p>-->
</div>
</div>
<!-- end post -->
so I am trying to add a new row after every 4th gallery and continue on until I am out of galleries to add. So if there is 17 galleries there will be 4 rows of 4 galleries and 1 row of the remaining gallery. here is an example of how it looks: http://www.csulb.edu/centers/latinohealth/media/galleries/
here is my code:
<?php $this->start_element('nextgen_gallery.gallery_container', 'container', $displayed_gallery); ?>
<div class="row-fluid secondone">
<div class="ngg-albumoverview span12">
<div class="row-fluid">
<?php $count = 0;?>
<?php foreach ($galleries as $gallery) {
$count++;
?>
<div class="ngg-album span3">
<div class="ngg-albumtitle">
<?php echo_safe_html($gallery->title); ?>
</div>
<div class="ngg-albumcontent">
<div class="ngg-thumbnail">
<a class="gallery_link" href="<?php echo nextgen_esc_url($gallery->pagelink); ?>"><img class="Thumb" alt="<?php echo esc_attr($gallery->title); ?>" src="<?php echo nextgen_esc_url($gallery->previewurl); ?>"/></a>
</div>
<div class="ngg-description">
<p><?php echo_safe_html($gallery->galdesc); ?></p>
<?php if (isset($gallery->counter) && $gallery->counter > 0) { ?>
<p><strong><?php echo $gallery->counter; ?></strong> <?php _e('Photos', 'nggallery'); ?></p>
<?php } ?>
</div>
</div>
</div>
<?php if ($count % 4 == 0 ) ?>
</div>
<div class="row-fluid">
<?php } ?>
</div>
</div>
</div>
<?php $this->end_element(); ?>
Found the problem:
the row:
<?php if ($count % 4 == 0 ) ?>
should be:
<?php if ($count % 4 == 0 ) { ?>
You need to do what you want with css styles, not with the php.
Create a container block with fixed width that can contain exacly 4 galleries and use the float property on the boxes of the galleries.
I've made a repeat region with dreamweaver and the result is this:
<div>
<?php do { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</div>
No problem here, it works fine.
The thing is, I'm trying to use only 5 slides for each page, something like this:
<div>
<div class="page">
<?php do { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php
$i = 0;
$r = $i % 5;
$i++;
if ( $r == 0 ) {
?>
</div> <!-- closes div.page -->
<div class="page"> <!-- adds a new div.page -->
<? } ?>
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</div>
It's obviously not working, but hopefully you'll see what I'm trying to reach.
Thanks in advance!
UPDATE:
The result i get is:
<div class="page">
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
</div>
I would like it to be:
<div class="page">
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
</div>
<div class="page">
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide">...</div>
</div>
You're setting $i to 0 on every iteration. Place the $i = 0 before the do-while loop.
You should probably also place $i++ before $r = $i % 5; to get the result you require.
EDIT: You're also missing a closing brace before your while statement (typo?)
Hence, the complete code:
<div>
<div class="page">
<?php
$i = 0;
do { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php
$i++;
$r = $i % 5;
if ( $r == 0 ) {
?>
</div> <!-- closes div.page -->
<div class="page"> <!-- adds a new div.page -->
<?php
}
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</div>
the piece you gave is not a valid php code.
the line here:
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
opens a php tag without closing it before the next one you open.. so a first step would be to change that line to
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
also you missed closing a block, here:
<? } ?>
you should close both the if and the do/while block (so another })
another problem is the fact that on every step you change $i to 0, so every time $r will be 0 also
so in conclusion: take your problems step by step as you have more than one
<div>
<div class="page">
<?php for ($i = 0; $row_Recordset1 = mysql_fetch_assoc($Recordset1); $i++) { ?>
<div class="slide">
<img src="<?php echo $row_Recordset1['imagemUrl']; ?>" />
<h2><?php echo $row_Recordset1['titleProj']; ?></h2>
</div>
<?php if ( $i % 5 == 0 && $i ) { ?>
</div> <!-- closes div.page -->
<div class="page"> <!-- adds a new div.page -->
<?php } ?>
<?php } ?>
</div>
</div>
Something like this would loop through 5 times adding a new <div>content</div> to the variable $html. You can then echo the variable in your html body.
$html = "";
for ($i=0;$i<5;$i++) {
$html .= "<div class=\"page\">". $content[$i] . "</div>\n";
}
Additions:
<?PHP
while ($row_Recordset = mysql_fetch_assoc($Recordset1)) {
$html .= "<div class='page'>\n";
for ($i=0;$i<5;$i++) {
$html .= "<div class='slide'>". $row_Recordset[$i]['column'] . "</div>\n";
}
$html .= "</div>\n";
}
?>
This code will loop through the recordset populating $html on each iteration. Try echo $html and you will have an output structured as you want.