...

View Full Version : [HELP] Facebook Like Button for MySQL Entries



FatDank
06-14-2011, 11:51 AM
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
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

Fumigator
06-14-2011, 03:01 PM
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.


$result=mysql_query($query);
if (!$result)
{
die("Query Error! Query: $query<br>Error:".mysql_error());
}

FatDank
06-14-2011, 03:11 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum