if statement to execute when a link is clicked
Moderator: General Moderators
-
angrypenguin
- Forum Newbie
- Posts: 5
- Joined: Sun Dec 03, 2006 3:12 pm
if statement to execute when a link is clicked
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
Thanks very much
Andy
- potato
- Forum Contributor
- Posts: 192
- Joined: Tue Mar 16, 2004 8:30 am
- Location: my lovely trailer, next to the big tree
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...
<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...
-
klarinetking
- Forum Commoner
- Posts: 59
- Joined: Mon Jul 24, 2006 9:43 am
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:
And use the JS function to call info from the DB and echo it to the page.
klarinetking
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.
?>klarinetking
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?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...
Also, what does an if statement have to do with that?
-
klarinetking
- Forum Commoner
- Posts: 59
- Joined: Mon Jul 24, 2006 9:43 am
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
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.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
-
angrypenguin
- Forum Newbie
- Posts: 5
- Joined: Sun Dec 03, 2006 3:12 pm
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
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