Do list separated by date PHP - php

I need your help.
I'm creating a reporting system and I need it to list all the reports that groups only in blocks according to the date.
ex:
Today - May 23
a result
result 2
May 22
result 3
4 results
5 results
May 21
6 results
7 results
The listing I can do it quietly, the problem is to distinguish the date to be right within the respective block.
My code:
<?php
$data_anterior = "0000-00-00";
$data_hoje = date("Y-m-d");
//Se houverem registros
foreach($notificacoes AS $notif) :
?>
<?
//Verifica a data e faz o tratamento
$data_cadastro = date("Y-m-d", strtotime($notif->data_cadastro));
?>
<?php if($data_cadastro == $data_hoje && $data_anterior != $data_cadastro) { ?>
<h4>Hoje <span><?php echo $CI->funcoes->data_abreviada($data_cadastro); ?></span></h4>
<ul class="list-notificacoes">
<?php } ?>
<?php if($data_cadastro < $data_hoje && $data_anterior != $data_cadastro) { ?>
<div class="graybox">
<header class="clearfix">
<h4><?php echo $CI->funcoes->data_abreviada($data_cadastro); ?></h4>
Toggle
</header>
<ul class="list-notificacoes">
<?php } ?>
<li class="clearfix">
<div class="box-left">
<span class="icon-lista-ate"> </span>
<?php echo stripslashes($usuario->nome); ?>
<span>fez tal tarefa</span>
<?php echo stripslashes($evento->titulo); ?>
</div>
<div class="box-right">
<span><?php echo date("H:i", strtotime($notif->data_cadastro)); ?></span>
<a class="icon-close ir" href="">Excluir</a>
</div>
</li>
<?php if($data_cadastro == $data_hoje && $data_anterior != $data_cadastro) { ?>
</ul>
<?php } ?>
<?php if($data_cadastro < $data_hoje && $data_anterior != $data_cadastro) { ?>
</ul>
</div>
<?php } ?>
<?php $data_anterior = date("Y-m-d", strtotime($notif->data_cadastro)); ?>
<?php endforeach; ?>
My problem is with the closing of the blocks and thus it breaks the code.
There's something wrong in my IF, someone help me?

I think it is a typo.
After the foreach statement "php" is missing from the opening tag:
<? instead of
<?php
//Verifica a data e faz o tratamento
$data_cadastro = date("Y-m-d", strtotime($notif->data_cadastro));
?>)
See if this fixes your problem.

Related

DIv top to bottom listing

I need to list half portion of the for loop is to left side and other is in the next is right side.how to solve it?
foreach ( $events as $post ) {
$start_date = tribe_get_start_date( $post, false, 'F d, Y');
$end_date = tribe_get_end_date( $post, false, 'F d, Y');
if($i<=$number){
?>
<div class="col-md-61 leftDiv">
<div class="row1 outerDiv">
<li class="ecs-event">
<span class="duration time">
<span class="tribe-event-date-start"><?php if(!empty($start_date)) { ?> <?php echo $start_date; ?> <?php } ?> <?php if(!empty($end_date) && $start_date != $end_date ) { ?> - <?php echo $end_date; ?> <?php } ?> </span>
</span><span class="duration venue"><em>
at </em><?php echo tribe_get_venue( $post ); ?></span>
<h4 class="entry-title summary"><?php echo $post->post_title; ?>
</h4>
</li>
</div>
</div>
<?php } else {
?>
<div class="col-md-61 rightDiv">
<div class="row1 outerDiv">
<li class="ecs-event">
<span class="duration time">
<span class="tribe-event-date-start"><?php if(!empty($start_date)) { ?> <?php echo $start_date; ?> <?php } ?> <?php if(!empty($end_date) && $start_date != $end_date ) { ?> - <?php echo $end_date; ?> <?php } ?> </span>
</span><span class="duration venue"><em>
at </em><?php echo tribe_get_venue( $post ); ?></span>
<h4 class="entry-title summary"><?php echo $post->post_title; ?>
</h4>
</li>
</div>
</div>
<?php }?>
<?php
} ?>
please help to do that.I mean top to bottom listing as side by side
To point you to the idea you can check for even or odd item numbers to distribute your items.
Here is a generic code:
$even = [];
$odd = [];
foreach(range(1,10) as $value) {
if($value % 2 === 0) {
// even divisable by 2 without rest
$even[] = $value;
continue;
}
$odd[] = $value;
}

PHP if else statement producing unwanted line breaks

I'm using a PHP if else statement to ignore a custom field 'thingstodo' if it's empty. I have got the following code to work but it's putting unwanted line-breaks after every paragraph tag in my content. Where am I going wrong?
<?php if (get_field('gettingthere')): ?>
<div class="inprofile3col">
<h2>Getting there</h2>
<span class="content">
<?php echo get_post_meta($post->ID, 'gettingthere', true); ?>
</span>
<?php endif; ?>
<!-- ends Getting there -->
<!-- Things to do begins -->
<?php if (get_field('thingstodo')): ?>
<h2>Things to do</h2>
<?php endif; ?>
<span class="content">
<?php
$value = get_field('thingstodo');
if ($value) {
echo $value;
} else {
echo '';
}
?>
</span>
</div>
Here
<span class="content">
<?php
$value = get_field('thingstodo');
if ($value ) {echo $value ;} else {echo '';}
?>
</span>
you still have an output if the field is empty: the empty span-tag:
<span class="content">
echo '';
</span>
You should remove line breaks from thingstodo and avoid empty html tags. Here is the updated mark up:
<?php if( get_field('gettingthere') ): ?>
<div class="inprofile3col">
<h2>Getting there</h2>
<span class="content">
<?php echo get_post_meta( $post->ID, 'gettingthere', true ) ; ?>
</span>
<?php endif; ?>
<!-- ends Getting there -->
<!-- Things to do begins -->
<?php if( get_field('thingstodo') && !empty(trim(get_field('thingstodo')))) { ?>
<h2>Things to do</h2>
<span class="content">
<?php
$value = preg_replace('/\s\s+/',' ',trim(get_field('thingstodo')));
if ($value) {echo $value ;} else {echo '';}
?>
</span>
<?php } ?>
</div>

Display nav list of content is available with php

I've got this PHP code:
<div class="connect_wrap <?php echo $this->class; ?> block" <?php echo $this->cssID; ?>>
<?php if(!$this->empty): ?>
<?php foreach($this->entries as $entry): ?>
<div class="entry block <?php echo $entry->class; ?>">
<div class="tab">
<ul class="tabs">
<li class="tab-link current" data-tab="Kunden">Kunden</li>
<li class="tab-link" data-tab="Loesungen">Lösungen</li>
</ul>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM kunden WHERE partner=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Kunden" class="tab-content current">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/kunden-detail/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM solutions WHERE solution_provider=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Loesungen" class="tab-content">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/synaptic-commerce-solution/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
In that code, I've got two DB queries. My problem is, if there is no data for both queries, the div with the class "connect_wrap" should not be displayed.
How can I do that?
Thanks in advance.
do you want to check if the query has data in it and its not empty ? if so try num_rows it will return the number of rows that the query found/affected for example to check if th query returned one or more rows
if($result->num_rows >= 1) {
//do stuf
} else {
// no result found
}
Move the query execution up or preferably: not within the html but in a different file/class. Then add a check before the content_wrap div: if($kundenResult->num_rows >= 1 || $solutionsResult->num_rows >= 1). If you just keep the individual checks like you already have, it will only show the content_wrap div if either or both of the queries return rows of data.

Place DIV's in a containing DIV based on a numeric value

Ive got the follow PHP:
<div class="slide-background">
<div class="slide">
<?php foreach (array_chunk($items->submenu, $linkCount) as $items): ?>
<?php if (12 / $cols == 1):?>
<div class="col-md-12">
<?php else: ?>
<div class="col-md-<?php echo 12 / $cols; ?>">
<?php endif; ?>
<ul>
<?php foreach($items as $submenu): ?>
<?php echo $submenu; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
<ul class="pager">
<li>prev</li>
<li>next</li>
</ul>
</div>
</div>
basically it calculates how many links to display and how many columns, but i now need to place the links in <div class="slide"></div>, but based on the columns.. so basically i need to say if $cols = 2 place two div's in a div and close.. so its basically how many every $cols it should place so many div's in that div..
Its Confusing for me to even explain.. I think Ive explained it rather well above.. If not place say so and ill try again..
Any Help Greatly Appreciated..
UPDATE:
thanks to Hans ive now have the following:
<?php $linksPerColumn = ceil($linkCount / $cols); $linkCounter = 0;?>
<div class="slide-background">
<div class="slide">
<div class="col-md-<?php echo 12 / $cols ?>">
<ul>
<?php foreach ($items->submenu as $link): ?>
<?php $linkCounter++;?>
<?php if($linkCounter % $linksPerColumn == 0):?>
</ul>
</div>
<div class="col-md-<?php echo 12 / $cols ?>">
<ul>
<?php endif; ?>
<?php echo $link; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
<ul class="pager">
<li>prev</li>
<li>next</li>
</ul>
</div>
</div>
only problem is when there's only one column and i need 2 links and then for it to close the div and the ul and start new ones.. right now it does that except for everyone and not for every two links...
You could use modulus for this one. You should calculate how many items you need per column. And then create a close and open div for example:
<?
$linksPerColumn = 4;
if ($linkCount > 4){
$linksPerColumn = ceil ($linkCount / $amountOfColums);
}
$linkCounter = 0;
?>
<div class="slide-background">
<div class="slide">
<?
foreach ($links as $link)
{
$linkCounter++;
?>
// Do your HTML Here.
<?
if($linkCounter % $linksPerColumn = 0)
{
?>
</div>
<div class="slide">
<?
}
?>
</div>
</div>
// Rest of the HTML here.
I think this should do the trick for you.

PHP content in HTML Code with If conditon

I am trying to show text content just with a PHP if condition but I have several errors and I don’t see where is the error could someone help me with this, here is the code:
<?php
if(
isset($_POST['send']) &&
!validateDiscp($_POST['Discp']) || !validateSize($_POST['Size'])
) : ?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])):?>
<li><strong>Discription:</strong>Discription need to be larger then 10!</li>
<?php endif?>
<?php if(!validateSize($_POST['Size'])):?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php endif ?>
</ul>
</div>
<?php elseif(isset($_POST['send'])):?>
<div id="error" class="valid">
<ul>
<li><strong>Congratulations!</strong> All fields are OK ;)</li>
</ul>
</div>
<?php endif ;?>
I would rewrite the whole outside block. Instead do:
<? if( isset($_POST['send'])&& !validateDiscp($_POST['Discp']) || !validateSize($_POST['Size']) ) { ?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])) { ?>
<li><strong>Discription:</strong> Discription need to be larger then 10!</li>
<?php } ?>
<?php if(!validateSize($_POST['Size'])) { ?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php } else {
$nothing = true;
?>
</ul>
</div>
<?php if( isset( $nothing ) and isset($_POST['send'] ) ) { ?>
<div id="error" class="valid">
<ul>
<li><strong>Congratulations!</strong> All fields are OK ;)</li>
</ul>
</div>
<? } ?>
I think the flaw in your logic ist hat you have an else statement that is dangling. Instead add a little logic to detect when the else case is hit and add your additional logic and your good to go.
All the endifs need to have ; after them. Also, I'm not sure if this is an actual error or just the code getting wrapped, but make sure your first if is all on one line.
after changing things it is working here is the code
<?php if(isset($_POST['send']) && !validateDiscp($_POST['Discp'])|| !validateSize($_POST['Size']) ):?>
<div id="error">
<ul>
<?php if(!validateDiscp($_POST['Discp'])):?>
<li><strong>Discription:</strong> Discription need to be larger then 10!</li>
<?php endif;?>
<?php if(!validateSize($_POST['Size'])):?>
<li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
<?php endif; ?>
</ul>
</div>
<?php elseif(isset($_POST['send']) ):?>

Categories