Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation [HELP] Facebook Like Button for MySQL Entries

    Hi guys. I am in a real pickle here. I am trying to make a website where;

    - Anyone can leave a status
    - Have the facebook like button on each status

    However I cant seem to achieve this. I can get the like button under each status but as soon as one is clicked they are all clicked.

    I hope someone can help.

    Here is what I have:

    PHP Code:
    <?php
    mysql_connect
    ($localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $status="SELECT * FROM comments WHERE 'id'";
    if (
    $_GET['$status'] == "$id")

    $query="SELECT * FROM comments";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();


    echo 
    "<b>Database Output</b><br><br>";

    $i=0;
    while (
    $i $num) {

    $id=mysql_result($result,$i,"id");
    $comment=mysql_result($result,$i,"post");

    echo 
    "<b>($id)</b> $comment<br>";

    echo 
    "<div class='fb_like'> 
    <fb:like width='340' layout='standard' show_faces='false' href='<?php the_permalink(); ?>' colorscheme='default'></fb:like> 
    </div> <br><hr>"
    ;


    $i++;
    }
    ?>
    Where I have <?php the_permalink(); ?> I need it to somehow have its own url if that makes sense. So say localhost/post.php?id=1
    Last edited by FatDank; 06-14-2011 at 01:23 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I think you have your answer already, just use a query string with the value of $id in it.

    But I see much more wrong with your PHP script than the one thing you're asking about. For starters, your line 5 "if" statement's true block is not enclosed by squiggly brackets so by default it's only one statement long, the assignment of $query. But then you use that variable in the next statement so this is obviously not what you want to do.

    And the value of $_GET['$status']? Probably not what you're thinking it should be.

    And a nag: Whenever you call mysql_query(), you need to check the return value. FALSE means the query did not work, TRUE means it worked. This is a VERY IMPORTANT thing to check. You never want to assume a query just worked.
    PHP Code:
    $result=mysql_query($query);
    if (!
    $result)
    {
        die(
    "Query Error! Query: $query<br>Error:".mysql_error());


  • #3
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry im new to PHP.
    Im using $_GET['$status'] to try get the url post.php?status=1 so for the facebook like button in the href i would have something like post.php?status=$id

    I also need it so that each status can have its own url somehow

    Can you fix the code up so it does that or point me in the right direction before my head explodes :P
    Last edited by FatDank; 06-14-2011 at 03:17 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •