Add a close/open java klappe to the news box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
graaf
Forum Newbie
Posts: 4
Joined: Wed Jan 07, 2015 11:51 am

Add a close/open java klappe to the news box

Post by graaf »

I have news box in index.php and now I get working open/close news, but I need some help.

I wanted first 2 items expanded and others in closed. I'm very thankfull who can help me with this problem

My news code

Code: Select all

 print("<table class='main' border='0' width='100%' cellspacing='0' cellpadding='0'><tr><td class='embedded'>");
    print("<h2>Site news</h2>\n");

    $news_file = CACHE_DIR."news.txt";
    $expire    = 15 * 60; # 15 Min

    if (file_exists($news_file) && filemtime($news_file) > (time() - $expire)) {
        $news2 = unserialize(file_get_contents($news_file));
    } else {
        $res = mysql_query("SELECT id,userid,added,body,title FROM news WHERE added + ( 3600 *24 *45 ) > ".time()." ORDER BY added DESC LIMIT 10") or sqlerr(__FILE__, __LINE__);

        while ($news1 = mysql_fetch_assoc($res)) {
            $news2[] = $news1;
			$news_flag = 0;
        }

        $output = serialize($news2);
        $fp     = fopen($news_file, "w");

        fputs($fp, $output);
        fclose($fp);
    }

       if ($news2) {
        
	print("<table border='1' width='100%' cellspacing='0' cellpadding='10'><tr><td class='text'>\n<ul style='list-style: none;'>");
        
foreach ($news2 AS $array) {
	// Show first 2 items expanded
if ($news_flag < 2) {
$disp = "block";
$pic = "minus";
} else {
$disp = "none";
$pic = "plus";
}
 
 
        print("<br /><li><a href=\"javascript: klappe_news('a1".$array['id']."')\">");
	print("<li>- <strong>".format_comment($array['title'],0)."</strong> [".gmdate("d.m.Y", strtotime($array['added']))."]</li>");
        print("<li><div id=\"ka1".$array['id']."\" style=\"display: none\"> ".format_comment($array['body'], 0));
	print("<br />");

   
$news_flag++;
            print("</li>");
			
        }
        print("</ul></td></tr></table>\n");
    }
} 
Javaklappe code:

Code: Select all

function klappe(id) {
    var klappText = document.getElementById('k' + id);
    var klappBild = document.getElementById('pic' + id);
    if (klappText.style.display == 'none') {
        klappText.style.display = 'block';
    } else {
        klappText.style.display = 'none';
    }
}
function klappe_descr(id) {
    var klappText = document.getElementById('k' + id);
    if (klappText.style.display == 'none') {
        klappText.style.display = '';
    } else {
        klappText.style.display = 'none';
    }
}
function klappe_news(id) {
    var klappText = document.getElementById('k' + id);
    var klappBild = document.getElementById('pic' + id);
    if (klappText.style.display == 'none') {
        klappText.style.display = 'block';
        klappBild.src = '/img/minus.png';
    } else {
        klappText.style.display = 'none';
        klappBild.src = '/img/plus.png';
    }
}
function klappe_changelog(id) {
    var klappText = document.getElementById('k' + id);
    var klappBild = document.getElementById('pic' + id);
    if (klappText.style.display == 'none') {
        klappText.style.display = 'block';
        klappBild.src = '/img/minus.png';
    } else {
        klappText.style.display = 'none';
        klappBild.src = '/img/plus.png';
    }
}
graaf
Forum Newbie
Posts: 4
Joined: Wed Jan 07, 2015 11:51 am

Re: Add a close/open java klappe to the news box

Post by graaf »

Any help please?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add a close/open java klappe to the news box

Post by Celauran »

Something like this? http://jsfiddle.net/c24csw5r/
graaf
Forum Newbie
Posts: 4
Joined: Wed Jan 07, 2015 11:51 am

Re: Add a close/open java klappe to the news box

Post by graaf »

Celauran wrote:Something like this? http://jsfiddle.net/c24csw5r/
Yeah just like that. I added css and js in index.php, but something not right for the code.

Code: Select all

print("<table border='1' width='100%' cellspacing='0' cellpadding='10'><tr><td class='text'>\n<ul>");
        
foreach ($news2 AS $array) {

	print("<li><p><a href='#'>- <strong>".format_comment($array['title'],0)."</strong> [".gmdate("d.m.Y", strtotime($array['added']))."]</a>");
        print("".format_comment($array['body'], 0));
	print("<br />");
        print("</p></li>");			
        }
        print("</ul></td></tr></table>\n");
    }
} // END
It shows the first news item and other items is "hidden" and title not showing. + And when I click first news item it not hide the item.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add a close/open java klappe to the news box

Post by Celauran »

Did you just copy/paste, or did you look at my example and adapt it to your code?
graaf
Forum Newbie
Posts: 4
Joined: Wed Jan 07, 2015 11:51 am

Re: Add a close/open java klappe to the news box

Post by graaf »

Yeah I trying to get it working. Results = All my links not working in index.php etc...
Post Reply