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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation [HELP PLEASE] How do I give MySQL data its own url?

    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 Code:
    <?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++;
    }
    ?>
    Last edited by FatDank; 06-15-2011 at 01:35 AM.

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    is this the only part you are having difficulty with?

    Code:
    echo "<h1><a href='comments.php?id='>$comment</a></h1><br>";
    well I was going to suggest this next bit

    Code:
    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?

    Code:
    while ($i < $num) {
    hopefully that was of some use to you.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Code:
    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
    Code:
    $num=mysql_numrows($result);
    
    mysql_close();
    Which means that you can *NOT* do ANYTHING more with the database after the call to mysql_close !!!
    Last edited by Old Pedant; 06-15-2011 at 02:33 AM.

  • #4
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    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.
    Last edited by FatDank; 06-15-2011 at 03:13 AM.

  • #5
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by FatDank; 06-15-2011 at 03:23 PM.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Ahhh...can't help you. Dunno how you modify the contents of a facebook wall.

  • #7
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok no worrys. I think ive sorted the bulk of it now. Thanks anyway.


  •  

    Posting Permissions

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