Jump to content

how to add a close/open java klappe to the news box?...


rootKID

Recommended Posts

yoyo w3... im trying to build up a ''news'' box... and the messeages that comes out from my database are comming and all that... but what i wish it to do right now is to do like the picture down here: (ATTACHED... (NUMBER 1)) i wish to add a java-klappe script... i founded it here: http://www.koders.co....aspx?s=none#L6 i wish to do so i can click the news title, and then the news drop down (like the java klappe are supposed to do...). here is the original code i wish to use in this case:

 function klappe(id){var klappText = document.getElementById('k' + id);var klappBild = document.getElementById('pic' + id);  if (klappText.style.display == 'none') {   klappText.style.display = 'block';   // klappBild.src = 'images/blank.gif';}else {   klappText.style.display = 'none';   // klappBild.src = 'images/blank.gif';}} 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 = 'pic/minus.gif';}else {   klappText.style.display = 'none';   klappBild.src = 'pic/plus.gif';}}

its just how to add it into the word... i mean,... how to insert it so it works with the code i have gathered/coded... here is what i've coded so far in the news box...:

<?php$news_query = "SELECT n_headline,n_text FROM news";$news_result = mysql_query($news_query)or die(mysql_error());while($n_row = mysql_fetch_assoc($news_result)){echo $n_row['n_headline'];echo "<br />";echo $n_row['n_text'];}?>

so... hoping someone can help me integrade this code so it will work :)... thanks... :).

Edited by rootKID
Link to comment
Share on other sites

The klappe_news function takes an id as a parameter, and gets elements called "k" and "pic" with the ID after them. So if the ID is 10, it gets k10 and pic10. The k element is the text that you want to appear or disappear, and the pic element is the plus/minus icon. So, your PHP code will need to keep a counter to use for the ID, e.g.:

$id = 1;while($n_row = mysql_fetch_assoc($news_result)){  echo $n_row['n_headline'];  echo "<br />";  echo $n_row['n_text'];  $id++;}

So now you can use that ID for your elements:

echo '<div id="k' . $id . '">' . $n_row['n_text'] . '</div>';

You need to add the plus/minus image and give that an ID starting with "pic", and you can wrap a link tag around the image and the headline that runs the Javascript function and passes it the ID for that item.

Link to comment
Share on other sites

hello jsg... i did as you told me to do. but im just getting the normal output as before... this is the code i putted in...

<?php$news_query = "SELECT n_headline,n_text FROM news";$news_result = mysql_query($news_query)or die(mysql_error());/*while($n_row = mysql_fetch_assoc($news_result)){echo $n_row['n_headline'];echo "<br />";echo $n_row['n_text'];}*/$id = 1;while($n_row = mysql_fetch_assoc($news_result)){  echo $n_row['n_headline'];  echo "<br />";  echo $n_row['n_text'];  $id++;}echo '<div id="k' . $id . '">' . $n_row['n_text'] . '</div>';?>

and after that then i've maked the folder (pic) with the images in it called plus.gif and minus.gif... ideas?... (Note)...i can send all the files i have over mediafire if you would like to take a look at them... :).

Link to comment
Share on other sites

hey jsg... ive tried to move the picture to an another location also... and edit the JS file and PHP file... still the same... here is the diffrent codes now:

function klappe(id){var klappText = document.getElementById('k' + id);var klappBild = document.getElementById('pic' + id);if (klappText.style.display == 'none') {    klappText.style.display = 'block';    // klappBild.src = 'images/blank.gif';}else {    klappText.style.display = 'none';    // klappBild.src = 'images/blank.gif';}}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 = 'styles/images/backgrounds/icons/minus.gif';}else {    klappText.style.display = 'none';    klappBild.src = 'styles/images/backgrounds/icons/plus.gif';}}

<?php$news_query = "SELECT n_headline,n_text FROM news";$news_result = mysql_query($news_query)or die(mysql_error());/*while($n_row = mysql_fetch_assoc($news_result)){echo $n_row['n_headline'];echo "<br />";echo $n_row['n_text'];}*/ $id = 1;while($n_row = mysql_fetch_assoc($news_result)){  /*echo $n_row['n_headline'];  echo "<br />";  echo $n_row['n_text'];*/  $id++;  echo '<div id="k' . $id . '">' . $n_row['n_text'] . '</div>';}?>

Ideas?...

Link to comment
Share on other sites

lol... really?... no answers?....i mean... thanks for the try... but no solution yet ^^'...

Link to comment
Share on other sites

The code in post 4 is better than the code in post 3, but I would suggest incrementing the $id variable after everything else in the loop. You also need to add the code yourself to display the image next to the headline, and wrap both the image and headline text inside an <a> tag which calls the Javascript function. I showed the line of code to write the text as an example of using $id in the element's ID, you still need to add the <img> and <a> elements and set the <a> element to call the Javascript function.

lol... really?... no answers?.... i mean... thanks for the try... but no solution yet ^^'...
Oddly enough, I don't spend my weekends sitting in front of my computer just waiting to answer questions.
Link to comment
Share on other sites

sorry... just me that are trying to be rude again... sorry, just hate waiting on answers when somfthing fails :).. but i will try again... i will post feedback later! :). EDIT: how to add a link that calls the function? :/... i mean... i knew how to add a image (with) a (a href='') link... but that calls a function?... how?... can you give a example... i will try myself later... but just in case i do wrong... i will post my code later also... in that way you can see im not cheating lol :P..

Edited by rootKID
Link to comment
Share on other sites

Hey JSG... just tried a method that i got error with... and now i was trying yours... just almost working :)... see a picture... and how i was integrate your code with my:

echo '<div id="k' . $id . '"><a href="javascript: klappe_news("a'.$array['id'].'");">' . $n_row['n_text'] . '</a></div>';

just that when i click the link, then nofthing happends... that... plus it does not shows up the ID (k++) i have given it... just the name (Javascript(...) and thats it :/...ideas?... DUMP: just for asking... why would you use a button if you would have (Alot) news at one time... then you would use a button on each news?... orr am i missing somfthing :/?..

Edited by rootKID
Link to comment
Share on other sites

You probably want the link outside of the div, the div will get hidden so if you have the link inside the div you won't be able to un-hide it. I'm not sure what $array contains, you probably want to use $id for the id to send to the function. The quotes are a little messed up too, in fact you shouldn't need quotes around the parameter at all since it's a number: klappe_news('.$id.');

Link to comment
Share on other sites

still not working... Code below:

echo '<a href="javascript: klappe_news("a'.$array['id'].'");"><div id="k' . $id . '">' . $n_row['n_text'] . '</div></a>';

Link to comment
Share on other sites

ok... got it working now... kinda... when i click the link... well... then its just going gone... dis-appearing for some kinda reason... Pics added below... CODE BELOW:

echo '<a href="javascript: klappe_news('.$id.');"><div id="k'.$id.'">'.$n_row['n_text'].'</div></a>';

Edited by rootKID
Link to comment
Share on other sites

Right, it disappears, that's what you're telling it to do. You have the link over the body text right now. If you want to reproduce the original then the link should be on the headline and the plus/minus image instead of the text.

Link to comment
Share on other sites

what if i wish both on?... the text (and picture?)... and by the way... i did try that, to add the link inside the div box and around the text... and still dis-appeared... :/... Like so:

echo '<div id="k'.$id.'"><a href="javascript: klappe_news('.$id.');">'.$n_row['n_text'].'</a></div>';

Link to comment
Share on other sites

You can have more than one link but if you only have the text and nothing else you're not going to be able to show the div again. You need to add the headline and the image outside of the div that gets hidden and put a link on that. You can also put a link on the body text if you want to, it doesn't matter to me.

Link to comment
Share on other sites

ahh... so just to assamble what ive learned so far... lol... 1. the link should be around the link (text)...2. the link (text) should be outside the div...3. the div for itself (with) a ID... 4. will post feedback and see how it wents now :)... EDIT: ok... it all works damn nice well now! FREAKING THANKS! the only thing.. if you know how.. the messeage is going to be shown in the beginning of the showing of the page... how can i do so that not is going to happend?...i mean... so the people HAS to click on the link to see the news...?...

Edited by rootKID
Link to comment
Share on other sites

Thanks alot bro!... it works now :)... just what i was going to point for :D... nice :P... now just an another question... that is a little bit diffrent... i dont know if you know this source: www.tbdev.net...but its a Torrent Source... and the modifications they have are the once im trying to convert... some of the at least :)... anyways... the point is that when i see this at my SQL:

$news_query = "SELECT n_headline,n_text FROM news";

now how can i do so it will only show stuff like 12 to like 30 days... this is the code from tbdev:

$news_expanded = "SELECT * FROM news WHERE added + ( 3600 *24 *45 ) >".time()." ORDER BY added DESC LIMIT 10";

and they have done it as i can see it...now... the question... what shall i add to my query before this also can happend?... EDIT: i will check back tomorrow... is a little tired... hoping a answer soon made :)... thanks in anyways if you can't ;)...

Edited by rootKID
Link to comment
Share on other sites

If you want it to be like that, then your table needs a column to store the date for the article in a Unix timestamp format, so it needs to be an int column. You can get the current timestamp with the time function like they used when you insert a new article.

Link to comment
Share on other sites

hmm. ok, thanks... ill think i just use this as it is now and trying to upgrade in the next version :P... trying to build a bigger system builded on Versions :P... trying to build up Version .001 :D:D:D... anyways.,. thanks! :).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...