Jump to content


Photo

Creating a list


  • Please log in to reply
4 replies to this topic

#1 Bobsterize

Bobsterize
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 August 2006 - 04:47 PM

Hello guys,

First I must say, good job on the website, I really like it and it's happy to see fellow programmers/hackers willing to help others with php.
I learned html and javascript at the college and PHP is this coming semester, but honestly I can't wait. :)
Well, let me get right to it.
I am building a simple website that has 3-4 textboxes (Name, Address,...) and 1 button that will say Add or Submit.
Now each time a user goes to my website, fills in these information and clicks add, it will add his information to a list, and the list will keep growing with each user adding his info to the list.
The list can be on the same page or a different page and it is a public list that anyone who accesses the website can see the names of everyone and location.

EXAMPLE:
John Smith Ontario Canada
Angela Donavin California USA
.
.
.

Now I have a hosting plan with Mysql but writing the information to a textfile works too.

If I can get some help on how about doing that, I will pretty much appreciate it.

Thanks a lot and keep up the good work.

~Bob

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 05:06 PM

Do you intent to display this list as soon as anyone visits your site?
And do you plan to read all these names from the file each time someone visits your start page.
Or do you provide the list of names when someone clicks a button on your site?
I agree that, for the moment, you could do with a text file. Possibly an XML or just plain text?

If I can be of help, holler!

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 Bobsterize

Bobsterize
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 August 2006 - 06:03 PM

Hey Ronald,
Yeah man, the list keeps updating everytime someone adds to it, and it will show right under the textboxes for everyone to see.

Example:
I go in the website.
I see 3-4 textboxes and a huge list of names under it
I fill in the textboxes, click add.
It will refresh the page (unless It doesnt need to refresh) and I will now see my name in the list along with everyone else.

The new user that added his name will apear on top of the list, so technically it's sorted by newed to older and possibly a date and time beside it when they added their names.

Thanks.

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 07:02 PM

Try this one for a start:

Before anyone shoots me:
1. There is no input cleansing
2. no check if file exists
3. no error checking

<?php
$fn = "myfile.txt";
	
if (isset($_POST['_submit'])) {
  $text = array();	
  // append you next entry to the file  
  $fh = fopen ($fn, 'a');
  fwrite ($fh, date("Y-m-d H:i:s ").$_POST['data']."\n");
  fclose ($fh);
}
  // read the file into an array, one line per array entry, sort reverse
  $text = file ($fn);
  rsort($text); 
  echo '<div style="position:absolute;top: 70px;">';
  for ($i=0; $i<count($text); $i++)
    echo $text[$i] . '<br />';
  echo '</div>';
  
  echo '<form name="myform" method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  echo 'Add your name:<br />'; 
  echo '<input type="text" name="data" />';
  echo '<input type="hidden" name="_submit" value="1"/>';
  echo '<input type="submit" value="Add!" />';
  echo '</form>';
?>

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#5 Bobsterize

Bobsterize
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 August 2006 - 08:02 PM

I will give it a try and let you know.
Thanks a lot.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users