#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    18
    Rep Power
    0

    php/mysql comment system on blog.


    Hey, been lurking on the boards for a while getting great info from everyone, but finally i'm really stuck on something.

    This is the first real time I did something major in php, so bare with me.

    I am having trouble passing a blogger specific dynamic variable into a php variable so that I can use it (see below for code blurb). I'm not sure if it can even be done but I figure I should ask you guys.

    I created a commenting form with php and mysql on my website. See it here

    If you click on the link above, you can see the "Click here to comment" link which will pop up another window where you can comment.

    It's pretty simple and everything works perfect, except I would like to implement a way for the comment link to actually display how many people have posted a comment already. So instead of the link "Click here to comment" it might say "3 Comments posted."

    Now, the way I have it set up, it passes the blogger's timestamp into the link as a php variable. That variable is then added as a field in the mysql database when a user fills out the form and also to pull any entries in the database from that specific timestamp.

    Here is a blurb from the index.php page with the blogger code that populates the blog page with entries:


    <!-- Blogger code begins here -->
    <blogger> <blogdateheader>
    <h4><b><$BlogDateHeaderDate$>:</b></h4>
    </blogdateheader>
    <p class="main"><$BlogItemBody$>
    <br>
    <small><$BlogItemAuthorNickname$> // <a href="<$BlogItemArchiveFileName$>#<$BlogItemNumber$>"><$BlogItemDateTime$></a></small>
    // <a href="javascript:void(0);" onClick="window.open('comments.php?blog_id=<$BlogItemDateTime$>', 'Comments', config='height=500,width=450,resizable=no,scrollbars, status, left=100, top=50')">Click here to Comment.</a>
    <br>
    <center>
    __________________________________________________
    </center>
    <br>
    </p>
    </blogger>
    <!-- Blogger code ends here -->
    The problem is, I can't seem to pass the blogger timestamp into a php variable within the page so that I can then use it to compare mysql data and count rows with the comments.

    <$BlogItemDateTime$> is what I'm trying to store as a variable. It can be passed on as a php variable if entered into a URL (which is what i did for the comment's page), just can't store it as a php variable within itself the index page.

    This is what i've tried to do:
    <?php $blogtimestamp = ?> <$BlogItemDateTime$> <?php ; ?>
    I know it's wrong, I just wanted to show you to give you an idea of what I'm trying to accomplish... if i had the timestamp in a php variable, then I could manipulate it.

    Sorry for such a long post, i had to explain it all.

    Thanks for any and all help.
  2. #2
  3. A happy helper
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Stavanger, Norway
    Posts
    457
    Rep Power
    16
    It looks as thought the blogger uses JavaScript and that the variable you want to access is a JavaScript-variable. If I'm mistaken in this assumption, please ignore the rest of my reply.

    If my assumption, however, is correct, then you must remember that all php-code is executed _on_ the server, before the javascript is executed on the _client_ afterwards. Thusly increasing the difficulty of your problem.

    It's solvable, but you have to turn the tables, so to speak. In other words, you need to have a javascript-solution which inserts a piece of text generated using php.

    I don't know javascript, but I've heard of some write.document-function, so something along the lines of (code will _not_ work, but you should get the idea):
    write.document("http://somewhere/countComments.php?timestamp=$BlogItemDateTime$")

    HTH, Holroy
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    18
    Rep Power
    0
    I see where you're going with this. I've been checking out other blog "commenting systems" to see how they did it, and this one site Haloscan seems to do what I want it to do:


    this is inserted into the head


    <script type="text/javascript" src="http://www.haloscan.com/load.php?user=mystic511"> </script>
    This is then added to make the comment link:
    <a href="javascript:HaloScan('<$BlogItemNumber$>');"><script type="text/javascript">postCount('<$BlogItemNumber$>'); </script></a>
    It looks like they're passing <$BlogItemNumber$> into a php file with a javascript function. I can't say for sure if they're using a mysql database too, but it's reasonable right?

    Anyone have any clue how they worked javascript and php together like that?
  6. #4
  7. A happy helper
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Stavanger, Norway
    Posts
    457
    Rep Power
    16
    Originally posted by Mystic511
    Anyone have any clue how they worked javascript and php together like that?
    Ah... I see the light as to how they have done it. Normally you would have something like:
    <script type="text/javascript">
    ... here goes your javascript ...
    </script>

    Instead they ask a php-script to deliver the contents of a javascript-block. And now this php-script is able to do whatever it wants, whilst finally outputting a javascript-block.

    That leads to the following possible solution:
    <script type="text/javascript" src="'countComments.php?blog_id=<$BlogItemDateTime$>'"></script>

    This script returns "javascript-code" like:
    var noComments = XXX;

    where XXX is generated within the php-script. And then you change "Click for comments to":
    <$noComments$> comments

    (Please excuse me, if I'm fumbling. But I've never liked or bother to understand javascript. So my examples here are based on the javascript samples provided. And I'm also quite sure that there does exist some javascript-code to display the result of an external call directly, and this should produce a nicer solution )

    HTH, :e)

IMN logo majestic logo threadwatch logo seochat tools logo