...

View Full Version : [HELP PLEASE] How do I give MySQL data its own url?



FatDank
06-15-2011, 01:32 AM
How can I give a comment out my database its own url like comment?id=1

I have search everything I can think of to try to do this but cant get my head around it.
Here is what I have:



<?php
$conn = mysql_connect ("","","") or die ('cannot connect to database error: '.mysql_error());
mysql_select_db ("localdb");

$comment = $_POST['Comment'];

if (isset($comment))
{
if(($comment=="")) {
echo 'You havnt wrote a anything?!?';
die ();
}

$sql = "INSERT INTO
`localdb`.`comments` (`id`,`post`)
VALUES (NULL,'".$comment."');";
mysql_query($sql);
$commentno = mysql_insert_id();


echo 'Comment successfully posted: <br />';
echo "<br /><B>Comment #:</B> $commentno";
echo "<br /><B>Comment:</B> $comment";
echo '<form method="post" action = "comments.php">';
echo '<Input Type="SUBMIT" value="Submit Another?"></form>';
}

else{

echo '<h2>Leave a comment...</h2>';
echo '<form method="post" action="comments.php">';
echo 'Comment: <br /> <TEXTAREA NAME = "Comment" rows="4" cols = "70"></textarea><br /><br />';
echo '<INPUT TYPE="SUBMIT" VALUE="Submit Comment"> <br /><br />';
echo '</form>';
}

echo '<br>';
echo '<div>';


$username="";
$password="";
$database="";

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$sql="SELECT * FROM comments WHERE id";

$query="SELECT * FROM comments WHERE id ORDER BY id DESC"; //Order by DESC
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


echo "<h2>Comments</h2><br><br>";

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

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

echo "<h1><a href='comments.php?id=[Dont Know How To Do This]'>$comment</a></h1><br>";



$i++;
}
?>

bazz
06-15-2011, 02:21 AM
is this the only part you are having difficulty with?



echo "<h1><a href='comments.php?id='>$comment</a></h1><br>";

well I was going to suggest this next bit



echo "<h1><a href='comments.php?id=$id'>$comment</a></h1><br>";


but where I am not a php person really, I see a few other bits of your code that I ain;t sure about.

if you have 12 rows, would this next bit not just deal with 11 of them?



while ($i < $num) {


hopefully that was of some use to you.

Old Pedant
06-15-2011, 02:31 AM
echo "<h1><a href=\"comments.php?id=" . $id . "\">$comment</a></h1><br>";


But why? You are already showing the entire comment. Why do you want to go to another page to see the same information?

*********

Also, you are doing

$num=mysql_numrows($result);

mysql_close();

Which means that you can *NOT* do ANYTHING more with the database after the call to mysql_close !!!

FatDank
06-15-2011, 02:51 AM
Which means that you can *NOT* do ANYTHING more with the database after the call to mysql_close !!!

Thanks for that. Im new to PHP and still learning.

Its either have it that way so when I click the comment it to takes me to a comments.php?id=1 its takes me to a page with just that comment on it.

Or another way is have it so when I click the comment it bring it to the top of the page? Although I can see that way being javascript or something.

I want the page with the comment on to have the comment as the page title if that makes sense.

FatDank
06-15-2011, 03:20 PM
What im trying to acheive is when someone likes the comment it will post the comment on there facebook wall.

eg:

John Smith likes [COMMENT] on [WEBSITE]

So far all im getting is

John Smith likes localhost/index.php?id=15 on localhost

Old Pedant
06-15-2011, 11:26 PM
Ahhh...can't help you. Dunno how you modify the contents of a facebook wall.

FatDank
06-16-2011, 07:44 PM
Ok no worrys. I think ive sorted the bulk of it now. Thanks anyway.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum