Showing Users comments

Using PHP to show users comments?

Page 1 of 1

6 Replies - 1657 Views - Last Post: 15 December 2008 - 08:03 PM Rate Topic: -----

#1 insinkerator  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-December 08

Showing Users comments

Post icon  Posted 15 December 2008 - 02:55 PM

So im making a website for a friend of mine... and im trying to add a feature for people to add comments to pictures......

so there is the HTML page with the picture on it

<html>
<head>
<style type="text/css">
body {background-color: black}
</style>
<script type="text/javascript">
<!-- hide from old browsers

function getValue(varcomment)
{
// First, we load the URL into a variable
var url = window.location.href;

// Next, split the url by the ?
var qparts = url.split("?");

// Check that there is a querystring, return "" if not
if (qparts.length == 0)
{
return "";
}

// Then find the querystring, everything after the ?
var query = qparts[1];

// Split the query string into variables (separates by &s)
var vars = query.split("&");

// Initialize the value with "" as default
var value = "";

// Iterate through vars, checking each one for varname
for (i=0;i<vars.length;i++)
{
// Split the variable by =, which splits name and value
var parts = vars[i].split("=");

// Check if the correct variable
if (parts[0] == varname)
{
// Load value into variable
value = parts[1];

// End the loop
break;
}
}

// Convert escape code
value = unescape(value);

// Convert "+"s to " "s
value.replace(/\+/g," ");

// Return the value
return value;
}

// end hide -->
</script>
</head>
<body>
<p align="center">
<img src="6396190827a9350354535l.jpg"
width="500" height="376"
</p>
<form action="posting.php" method="post">
  Comments:<br />
  <textarea name="comments" id="comments">
  Leave your comment here!
  </textarea><br />
  <input type="submit" value="Submit" />

</form>
<p style="font-family:verdana,arial,sans-serif;font-size:10px;">
</p>
<form action="posting.php" method="get">

<script type="text/javascript">
<!-- hide
var name = getValue("comment");
document.write(comment);
// end hide -->
</body>
</html>



Anything in script tags has been copied and pasted off other sites, obviously to no avail :(
real link = http://insinkerator....html?comment=kk

then that links to a file i have named posting.php

<form method="get" action="6396190827a9350354535l.html" name="comments"><input type="textarea" name="comment"></textarea><input type="submit" value="submit"></form>


Needless to say, it isnt working. Im a total beginner when it comes to this. As in a complete noob, so go easy on me!

Is This A Good Question/Topic? 0
  • +

Replies To: Showing Users comments

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Showing Users comments

Posted 15 December 2008 - 03:30 PM

You might consider storing the comments in a MySQL database. Then you can do something like this:

$query = sprintf("SELECT * FROM comments WHERE [insert conditionals here]");
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
  // HTML for each comment goes here, using array keys/values to designate where pieces go.  Like username, date/time, comment text, etc.
}



Hope this is useful for you :)

This post has been edited by Valek: 15 December 2008 - 03:31 PM

Was This Post Helpful? 0
  • +
  • -

#3 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Showing Users comments

Posted 15 December 2008 - 03:49 PM

If you're interested in seeing my User Comment system that i'm working on for my OS CMS, I can copy some in here. Otherwise I won't do this as the best way to learn is poke at it yourself.
Was This Post Helpful? 0
  • +
  • -

#4 insinkerator  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-December 08

Re: Showing Users comments

Posted 15 December 2008 - 04:02 PM

where do i put that code though?
Was This Post Helpful? 0
  • +
  • -

#5 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Showing Users comments

Posted 15 December 2008 - 04:04 PM

If you were asking that to Valek, that is just an example of how to query the database and write the comments to a MySQL database table.

To actually use that on an image, you would need to write more script to retrieve the info from the database, organize it, determine what comments belong on what images, ect.

Give it a shot :)
Was This Post Helpful? 0
  • +
  • -

#6 insinkerator  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-December 08

Re: Showing Users comments

Posted 15 December 2008 - 04:16 PM

oh boy that'll be fun......

is this all in PHP yeah?
Was This Post Helpful? 0
  • +
  • -

#7 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Showing Users comments

Posted 15 December 2008 - 08:03 PM

View Postpr4y, on 15 Dec, 2008 - 06:04 PM, said:

If you were asking that to Valek, that is just an example of how to query the database and write the comments to a MySQL database table.


Actually, the code I posted was an example of getting the comments information out of the database and displaying the same HTML for each comment in the database (meeting a certain set of criteria) with one while loop.

Quote

To actually use that on an image, you would need to write more script to retrieve the info from the database, organize it, determine what comments belong on what images, ect.


I don't think he's trying to put it on an image. I think he means he wants people to be able to look at pictures and leave comments about them. Please correct me if my understanding is wrong here, insinkerator.

View Postinsinkerator, on 15 Dec, 2008 - 06:16 PM, said:

oh boy that'll be fun......

is this all in PHP yeah?


Yeap, all of this is in PHP. To do this reliably, you're going to have to learn how to do MySQL manipulation in PHP. This is a tutorial on how to use PHP to manipulate a MySQL database. You can use these functions (and a knowledge of MySQL queries) to write the comments to the database, and pull them back out for display.

If you are unfamiliar with MySQL, a tutorial on that can be found here.

I hope this helps you get a better idea of what a comment system would take :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1