0

i have a php web application project ... and i want to implement a javascript onclick code .. for example : when user clicks follow this post ... the MySQL query inserts into database that the user followed this ... so the page is refreshed and after that it will appear as FOLLOWED .. what's the javascript code needed to do this ... or is there any example may fit ??

here's a sample code

     <div id="main_content">


        <?php

        if(isset($_GET['et']))
        {
        $et = $_GET['et'];
        }
        $result = mysql_query("select * from events where event_type =$et") ;

        require_once('queries/category_extract.php') ;

        ?>

        <div id="body_content">
    <div id="event_tag">
        <a><?php echo $cattitle["categ_title"]?>s</a>
    </div>

    <?php
    while($row=mysql_fetch_array($result) )
    {

        require('queries/followers_extract.php') 
        ?>



        <div id="postpreview">
        <div id="postpreview_up">
            <div id="postpreview_up_left">
                    <div id="postpreview_up_left_left">
                        <a>Event Title :</a>
                    </div>

                    <div id="postpreview_up_left_right">
                    <a><?php echo $row["event_title"] ?></a> 
                    </div>
            </div>

              <div id="postpreview_up_right">
                <img src="images/read_more.gif" />
              </div>
        </div>

        <div id="postpreview_bottom">
            <div id="postpreview_bottom_left">
                <div id="postpreview_bottom_left_left">
                <a>Date :</a>
                </div>

                <div id="postpreview_bottom_left_right">
                <a><?php echo $row["event_date"] ?></a>
                </div>
            </div>
        <div id="postpreview_bottom_right">

                <div id="postpreview_bottom_right_left">
                <?php

                if($follower['follower_id'] ==NULL){echo " <img src='images/follow_button.jpg' /> " ; } 
                    else { echo " <img src='images/follow_closed.jpg' /> " ;}
                ?>
                </div>

                <div id="postpreview_bottom_right_right">
                <?php
                if($follower['follower_id'] !=NULL){ echo " <img src='images/following_button.jpg' /> " ; } 
                else { echo " <img src='images/following_Closed.jpg' /> " ;}

                ?>
                </div>
                <div id="postpreview_bottom_right_right">
                <?php
                if($follower['follower_id'] !=NULL){ echo " <img src='images/unfollow_button.jpg' /> " ; } 
                else { echo " <img src='images/unfollow_closed.jpg' />  " ;}

                ?>

                </div>

        </div>

        </div>

        </div>

        <div id="splitter"></div>
        <?php
    }
    ?>
   <!--End Of Post Preview-->

     <!--End Of Post Preview-->
2
  • Generally, specifying what you've already tried and what your line of thinking is on what a possible solution might be etc. is needed for you to get help here. As it is, you're basically asking others to do all the work for you. That said, never use client-provided variables directly in SQL statements like that - it's a gaping security hole. Use prepared statements instead (Google it if you don't know what that is). Commented May 12, 2013 at 10:10
  • More to the point, some tips: If you want the page to refresh after the "follow" button/link has been clicked, then you don't need Javascript for that at all. If you would like to do what you describe without the page having to refresh I suggest you google "AJAX" and go through a tutorial or two about that. Commented May 12, 2013 at 10:14

1 Answer 1

2

ok go for this: http://www.9lessons.info/2009/04/exactly-twitter-like-follow-and-remove.html

you have to learn the basics as i read.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.