Page 1 of 1

if statement to execute when a link is clicked

Posted: Sun Dec 03, 2006 3:25 pm
by angrypenguin
Hi all, I'm trying to create a kind of drop-down section added to one of my blogs. I want it so that people can click on the 'COMMENTS' link and the code inside an if statement will be executed to display comments from my database. Does anyone know how to do this?

Thanks very much
Andy

Posted: Sun Dec 03, 2006 4:07 pm
by ok
I don't understand what you want it do. Please add more explanation and some code.

Posted: Sun Dec 03, 2006 5:24 pm
by potato
you make a link after each blog-story like this:

<a href='comments.php?blog=$blog'>View comments of this story</a>

where $blog has to be the id of the blog story.
on the comments page you make a mysql query:

SELECT * FROM comments WHERE blog_id = '$blog'

here the $blog is the $_GET['blog'] from your url.

hope that can help you...

Posted: Sun Dec 03, 2006 6:12 pm
by klarinetking
Are you looking for the code to be executed without another page load? If so, that means you'll have to use some sort of JavaScript.

Possibly something like:

Code: Select all

<?php
// Whatever code you have

echo '<a href="blah.com/" onclick="someFunction()">';
// Not tested at all.  Just a general concept.
?>
And use the JS function to call info from the DB and echo it to the page.

klarinetking

Posted: Sun Dec 03, 2006 7:52 pm
by califdon
Bevibed.be wrote:you make a link after each blog-story like this:

<a href='comments.php?blog=$blog'>View comments of this story</a>

where $blog has to be the id of the blog story.
on the comments page you make a mysql query:

SELECT * FROM comments WHERE blog_id = '$blog'

here the $blog is the $_GET['blog'] from your url.

hope that can help you...
As I understand what you want to do, you have it right there. On the first page, the viewer clicks on the link and the new page is generated by comments.php. What's your question?

Also, what does an if statement have to do with that?

Posted: Sun Dec 03, 2006 9:59 pm
by klarinetking
Hi,

Note that the first method posted will mean that users will be forced to go to another page to view comments. If you use JavaScript, the results can just appear when users click a link (kind of like GMail). It will take a lot more work, and will be more complicated than the first method. It is also possible to disable JavaScript entirely as well. In the end, it's your choice on how you want the feature to work.

klarinetking

Posted: Mon Dec 04, 2006 3:51 am
by ok
klarinetking wrote:Hi,

Note that the first method posted will mean that users will be forced to go to another page to view comments. If you use JavaScript, the results can just appear when users click a link (kind of like GMail). It will take a lot more work, and will be more complicated than the first method. It is also possible to disable JavaScript entirely as well. In the end, it's your choice on how you want the feature to work.

klarinetking
GMail uses AJAX http://developer.mozilla.org/en/docs/AJ ... ng_Started to connect to the server, get information from the DB and display it.

Posted: Mon Dec 04, 2006 6:51 am
by angrypenguin
wow, that's a hell of a lot to think about - thanks everyone. I really like the idea of using AJAX/javascript and I think that's the best way to go for what I want to achieve. Does anyone have a book on Javascript?... ;)

Andy

Posted: Mon Dec 04, 2006 8:57 am
by ok
You can learn from the web:
http://www.w3schools.com/js/default.asp - JavaScript tutorial
http://developer.mozilla.org/en/docs/JavaScript - JS basics
http://developer.mozilla.org/en/docs/AJ ... ng_Started - AJAX basics
http://script.aculo.us - AJAX framework
http://prototype.conio.net/ - Another AJAX framework
http://ajaxpatterns.org/PHP_Ajax_Frameworks - Lots of AJAX framework
viewtopic.php?t=54934 - This topic discusses AJAX frameworks