Notice

This old forum is now only available for consultation/read. User accounts on this old website are blocked.
Please create a new account on seblod.com and use the new forum http://www.seblod.com/community/forums.
Apologies for this perturbation and thank you for your understanding!
Welcome, Guest
Username Password: Remember me

If else in Advanced List
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: If else in Advanced List

If else in Advanced List 3 years, 3 months ago #1

  • quickmick
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hello Everybody.

I need some Help. (sorry for my bad english)

I want to display fields, if the field has the same content like a PHP variable.
If the content is not the Same, the Display a Text!

<?php
/**
* @version 1.7.0
* @author http://www.jseblod.com
* @copyright Copyright (C) 2009-2010 jSeblod. All Rights Reserved.
* @license GNU/GPL V2 License. http://www.jseblod-cck.com
* @package Advanced List (Auto, 2 Layouts) - jSeblod CCK ( Content Construction Kit )
**/

 
// No Direct Access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
 
<?php
// Init jSeblod Process Object { !Important; !Required; }
$jSeblod = clone $this;
if ( array_key_exists( 'cckitems', get_object_vars( $jSeblod ) ) ) {
$cckitems = $jSeblod->cckitems;
$cckwidth = @$jSeblod->cckwidth;
$columns = count( $cckitems );
if ( ! is_array( $cckwidth ) ) {
$col_width = ( $columns ) ? round( 100 / $columns ).'%' : null;
}
} else {
return true;
}
?>
 
<?php
// Init Style Parameters
include( dirname(__FILE__) . '/params.php' );
?>
 
 
 
<?php
// Die Standard-Zeitzone, die verwendet werden soll, setzen.
// Verfügbar seit PHP 5.1
date_default_timezone_set('UTC');
 
 
 
// Gibt etwas aus wie: 'Monday'
date('d.m.Y');
 
 
 
?>
 
 
 
<?php
$num = count( $jSeblod->list );
if ( $num) {
for ( $i = 0; $i < $num; $i++ ) {
?>
 
 
<?php
$a1 = date('d.m.');
$a2 = $jSeblod->list[$i]->geburtstag->value;
$a3 = substr($a2, 0, 6);
 
 
 
// geb datum
$a4 = substr($a2, 6, 10);
//real date
$a5 = date('Y');
$a6 = $a5-$a4;
 
?>
 
 
<?php
if ($a1 == $a3)
 
{
// START
echo "HAPPY BIRTHDAY";
echo '<br>';
echo 'Der HSV gratuliert zum ';
echo $a6;
echo '.Geburtstag!';
echo $jSeblod->list[$i]->title->value;
 
}
 
//ENDE
 
 
else {echo "LEER";}?>
 
 
<div>
<?php //echo $jSeblod->list[$i]->title->value; ?> <?php //echo $jSeblod->list[$i]->geburtstag->value; ?>
</div>
 
<?php
 
}
}
 
 
?>
 



So the problem is, i have the If else code IN the output table (LIST).
How can i get it outside?

example:
if field = a
display advanced List
else echo "TEXT or Whatever"

I Hope you know what i mean.

Thanks! an greeting from Germany!

Re: If else in Advanced List 3 years, 3 months ago #2

  • unleash.it
  • ( User )
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
Hey,

I'm not sure if I understand... is it that you are trying to check for a value in all of the articles of the content type.... and if it exists, play the list and if it doesn't, show some text? For that, you would probably have to run the FOR loop twice (first check for the value, then to display).

Do you have a live page so we can take a look?

If not, can you at least give a background of what you're doing (it sounds like you're going through a user content type and checking for a birthday?? Sorry, I don't know German...)
Last Edit: 3 years, 3 months ago by unleash.it.

Re: If else in Advanced List 3 years, 3 months ago #3

  • quickmick
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi unleash.it,

thank you for your fast answer!
Yes - I want to Display Birthdays, names....

I have a search, that display a content type.

i want to check in the template(advanced list)-> if Birthday = current Date -> then Display it (and some other fields.)
If not, Display a Text! But not for each row. only one Text.

I have no live page.
Can you give me some tips, how could it work for me?

Thanks! an greeting from Germany!
Last Edit: 3 years, 3 months ago by quickmick.

Re: If else in Advanced List 3 years, 3 months ago #4

  • unleash.it
  • ( User )
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
No problem quickmick and greetings to Germany from Berkeley, CA! I once spent a couple weeks Cologne and a town north of Hamburg and have some good memories.

Ok, correct me if I'm wrong. I think you're saying that you want to list out everyone who's birthday is "today"? Meaning, if more than one person has a birthday, list all of them? If I'm right about that, or if I can figure out what you're really trying to do I can probably help.

Assuming I am getting it, the if statement inside the loop looks in the right place. But some of the code I'm not sure of.

Here's some code that should work for checking if today's date:

if(date('d-m') == substr($jSeblod->list[$i]->geburtstag->value,x,y))

d-m sounds right for the date format (for Europe), but make sure it matches what you used in the field.

X should be the point in the date string where the month-day (or day-month) begins, and y the amount of characters to read. Do you have the right numbers? 10 for y seems too big.

Aside from that, are you sure you want to have an else statement here? What you're saying is that EACH AND EVERY time it's NOT someone's b'day to echo "LEER". (I wish I knew what leer means!) If you don't want to do that, you should take out this else.

Maybe you just want to echo "Leer" if no birthdays at all are found??? I can probably tell you how to do that if you can help my simple mind understand

Re: If else in Advanced List 3 years, 3 months ago #5

  • quickmick
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi unleash.it !

Berkeley CA ? CA = Califonia? Berkeley near San Francisco? Cool...

I think you're saying that you want to list out everyone who's birthday is "today"?

Thats correct...

Do you have the right numbers? 10 for y seems too big.

This is for calculate the Years. Example: Congratulations for your 81. Birthday
The input date is: 21.03.1990 (dd.mm.yyyy) - (char 6 to 10)

Aside from that, are you sure you want to have an else statement here?

I need a else statement after the loop. Finally I want to output this search in a Modul.
If i have 100 people in the list, i need only one Echo to say: Nobody has Birthday!


(I wish I knew what leer means!)

leer = empty

Maybe you just want to echo "Leer" if no birthdays at all are found???

Yes Leer is only a placeholder yet. Later i will display a text like this: " Nobody has Bithday today"

But I need only one echo after loop.

I hope you understand, what i want..

Thank you!!!

Re: If else in Advanced List 3 years, 3 months ago #6

  • unleash.it
  • ( User )
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
Great way to reply... I think I'll copy that.

Berkeley CA ? CA = Califonia? Berkeley near San Francisco? Cool...


Yeah, I guess I'm like most Americans. We always assume everyone else know our abbreviations (and everything about us)... Can see parts of SF out my window!

Do you have the right numbers? 10 for y seems too big.


This is for calculate the Years. Example: Congratulations for your 81. Birthday
The input date is: 21.03.1990 (dd.mm.yyyy) - (char 6 to 10)


When you're checking for the birthday, you should exclude years. That is part of the problem because someone's bday year will never occur again! So check for just day/month and no year in the IF statement. You can still say congratulations you're 81 but calculate the age separately. If your date is being stored as dd.mm.yyyy, your IF should look something like:

if(date('d.m') == substr($jSeblod->list[$i]->geburtstag->value,0,5)) {

$bdaycheck++; // this variable will be null unless there's at least one bday.

//echo your happy birthday stuff

} // that's it, no else here.

if (!$bdaycheck) echo 'leer';

Let me know if that works for you...

Finally I want to output this search in a Modul.


Assign the search and template to a list module and publish it to a position.

Hope that helps and I understood you ok.

Re: If else in Advanced List 3 years, 3 months ago #7

  • quickmick
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Yeah, I guess I'm like most Americans. We always assume everyone else know our abbreviations (and everything about us)... Can see parts of SF out my window!


mh, i know somethink about the states, NY = New York, CA= California. But only this, what i see in TV, TV News, Internet and in some tv Series. Thats all....

see Parts of SF? Golden Gate?

so back to the Problem....

I make a short test today and it looks like it should work:
This is the Code:

<?php
/**
* @version 1.7.0
* @author http://www.jseblod.com
* @copyright Copyright (C) 2009-2010 jSeblod. All Rights Reserved.
* @license GNU/GPL V2 License. http://www.jseblod-cck.com
* @package Advanced List (Auto, 2 Layouts) - jSeblod CCK ( Content Construction Kit )
**/

 
// No Direct Access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
 
<?php
// Init jSeblod Process Object { !Important; !Required; }
$jSeblod = clone $this;
if ( array_key_exists( 'cckitems', get_object_vars( $jSeblod ) ) ) {
$cckitems = $jSeblod->cckitems;
$cckwidth = @$jSeblod->cckwidth;
$columns = count( $cckitems );
if ( ! is_array( $cckwidth ) ) {
$col_width = ( $columns ) ? round( 100 / $columns ).'%' : null;
}
} else {
return true;
}
?>
 
<?php
// Init Style Parameters
include( dirname(__FILE__) . '/params.php' );
?>
 
 
 
<?php
// Die Standard-Zeitzone, die verwendet werden soll, setzen.
// Verfügbar seit PHP 5.1
date_default_timezone_set('UTC');
// Gibt etwas aus wie: 'Monday'
// echo date('d.m.y');
?>
 
 
 
 
 
 
<?php
$num = count( $jSeblod->list );
if ( $num) {
for ( $i = 0; $i < $num; $i++ ) { // loop
?>
 
 
<?php
$a1 = date('d.m.');
$a2 = $jSeblod->list[$i]->geburtstag->value;
$a3 = substr($a2, 0, 6);
// geb datum
$a4 = substr($a2, 6, 10);
//real date
$a5 = date('Y');
$a6 = $a5-$a4;
?>
 
 
<?php
if(date('d.m') == substr($jSeblod->list[$i]->geburtstag->value,0,5)) {
 
$bdaycheck++; // this variable will be null unless there's at least one bday.
 
echo " happy birthday dear ";
echo $jSeblod->list[$i]->title->value;
echo " to your ";
echo $a6;
echo ". birthday";
echo "</br>";
} // that's it, no else here.
// if (!$bdaycheck) echo 'empty';
?>
 
 
<?php // end loop
}
}
?>
 
<?php
// Output if nobody has birthday Today
if (!$bdaycheck) echo 'Nobody has birthday today';
?>


so i will test it again on monday and i hope it will work again (because other PC).
after that i will make this thread "solved"....

so finally: thank you for your amazing help.
greeting from "the heart of Germany" Thuringia... to Berkeley

Re: If else in Advanced List 3 years, 3 months ago #8

  • unleash.it
  • ( User )
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
Funny I was joking around, but I did it again... yes SF is San Francisco. Yeah, today was one of those rare awesome sunny days for the bay and I could see both the city and the golden gate very clear Hope the weather is good in Germany.

Basically without having access to the site, I am not good enough with PHP to simply look at it and say it will work or not. That's also why I am trying to help in pieces. But at a glace, there is some redundant code but what you did looks ok. Let me know...

FYI

<?php
$a1 = date('d.m.');
$a2 = $jSeblod->list[$i]->geburtstag->value;
$a3 = substr($a2, 0, 6);
// geb datum
$a4 = substr($a2, 6, 10);
//real date
$a5 = date('Y');
$a6 = $a5-$a4;
?>

Because I put the date check and geburtstag field directly into the if statement, you only need what $a4, $a5 and $a6 are doing (if in the end you code it like I did). But $a4 is wrong I think. So to get the person's age, I think you could combine them all into:

$yearsold = date('y')-(substr($jSeblod->list[$i]->geburtstag->value,6,4))

Assuming the bday is stored xx.xx.xxxx, The year starts on the 6th character (substr begins on 0 not 1) and goes for 4.
Last Edit: 3 years, 3 months ago by unleash.it.
  • Page:
  • 1
Time to create page: 0.36 seconds