View Full Version : output in mysql or text file?
Hey, I have made this script using ONE variable that the user defines like v=whatevertheywant using a form. What I want to do is when ever the variable 'v' has something put in for it, it not only echos() 'v' but it also stores that 'v' in a text file or mysql database and it will show all of the v's that have been inputed (maybe like a limit of the last 50 v's). Im sure this kind of thing isnt hard for any of you masters of php. THanks in advance!
I would suggest using mysql as it would be easier to manage (although a text file would be more reliable).
You are right . . . this would be simple. You can find many examples in books like "PHP & MySQL For Dummies", and a simple thing like this would be a great way to learn.
If you run into problems . . . post what you have and I am sure we can get you going to the next step.
Meh, I find books often too long and end up knowing too much than you need. I was wondering if someone could explain this more and maybe have a link to a site that explains how to do that specifically. I've made some stuff in mysql before but for what I want to do, make whatever is entered in 'v' is then echoed (know how to do that) but then on the same page it shows a list of all the v's that have been inputted from everyone that supplied something for this. I am not asking for a mysql tutorial, rather how to do something like this. Thanks for the suggestion though:) .
Originally posted by ndogg
. . . and end up knowing too much than you need.
Learning more than you need . . . yes, that would be a real bummer :)
For the last month I've been working with flatfiles to reduce the num of MySQl queries ( Due to PW limits ).
I find i both reliable and easy to work with now that I do the trick.
Flatfiles are more static though....!!!
To write to a flat file :
################
$your_content = "$name $fishtype $gender\n";
$filename = '/xxx/x/xxxxx/htdocs/xxxx/xxxx/testfile.txt';
$somecontent = $your_content;
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}
print "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
print "The file $filename is not writable";
}
#######################
Your info is now saved like this:
-------------------------------------------------------------------
Peter Pale Male
---- ---- -----
---- ---- -----
---- ---- -----
Call it back like this:
$fp = fopen('xxxxxxx/testfile.txt','r');
if (!$fp)
{
echo '<p>file not found or error opening file</p>';
exit;
}
$num = fgets($fp, 999); // drop first line
$i = 0;
while ( !feof($fp) AND $i++ < 2000 )
{
$num = fgets($fp, 999);
if( $i <= 1 ) continue;
$match = preg_split( "/[\t ]+/",$num ); // splitting the tabs and making each column readble
if( count($match)>0 ) {
$name[] = $match[0];
$fishtype[]= $match[1];
$gender[] = $match[2];
}
}
print_r ($name); // will return all names stored in the flatfile
In order to save to flatfile you'll have to execute/run the script. ( auto if there is a use of submit button )
Hope this can help you some of the way.
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.