Jul 26, 2008

A Few Things [php Fread, Fwrite]

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

A Few Things [php Fread, Fwrite]

robocz033
i am trying to learn fread, fwrite, and $_get for my form generator. this is my basic need:
a php script that will check a file named numbers.txt, read the information, input it into the file and erase the stuff in numbers.txt and replace it with a number 1 higher starting from 0.
since i have the fwrite script, that is fine, but to describe the whole thing, i need a script that will check numbers.txt, then use that number in a url (for posting a reply on a dedicated forum) so when a user presses post, it uses that url, instead of the same one. so after it gets the number, that number must be deleted from numbers.txt then replaced with 1 number higher.

So i guess it would go like this:
The url will have a php script, but i am not sure which one, i am guessing $_get that will retrieve a temporary number from numbers.txt and use that in a url.
Then when they hit post/submit, a script will erase numbers.txt and add a number that was 1 higher than the previous one.

I either need a full script or just some guidance. =)

Or another option is almost the same thing, but a script will check the database (i am not sure, but i think the post count would be there) for the post count, add one to it, and insert that temporarily into the url. i am not sure how possible that would be. but it would be nice not to upload another forum.

So this way would entitle:
A script within the url that will temporarily insert the post count plus one so the post is valid. (by post count, i mean the number of topics created). that pretty much sums up what would be needed. although i am not sure it is possible seeing as it would need to contact the database and find the total number of topics.

If it is any help, i use smf. i can also allow anyone who can help to use an administrator account on the forum to look at server information and stuff.

 

 

 


Reply

truefusion
The part about writing to a file and retrieving the information for later use and modifying the information is easy. The hard part is getting the forum script to work with it. I don't know my way around the SMF scripting or any other forum scripting. If having the forum script work with your script is a necessity, then i would suggest posting this in the support forum on the site of the makers of the forum.

Reply

galexcd
If you're using SQL to store the posts, there is a much easier way. The field you are using to hold the ID of the post, just make that an index, and set auto-increment. This way, sql will do all that work for you. Are you programing your own forums? If you are, PM me and i could give you some guidance on how the best way is to lay out all the tables, and how to have them work. Also, if you don't have an ID field, or i misunderstood you somehow, you could always get the total number of posts by
CODE
mysql_numrows($result);

where the variable result is the query of the table you are working with. I hope this helps, if not just reply here and i'll try to come up with a better answer. If you have any code already written that would be a help too. biggrin.gif

Reply

robocz033
well, i dont really understand what you said. however, i am not scripting my own forum, i use smf (i believe i mentioned that) but if you have any messenger, i can talk to you about it on wednesday because i am not going to be home at all tomorrow.

Reply

galexcd
Yes, well my AIM is in my profile and my msn uses my primary email so i'll pm you with that if you want.

Reply

hitmanblood
QUOTE(robocz033 @ May 14 2007, 12:46 AM) *
i am trying to learn fread, fwrite, and $_get for my form generator. this is my basic need:
a php script that will check a file named numbers.txt, read the information, input it into the file and erase the stuff in numbers.txt and replace it with a number 1 higher starting from 0.
since i have the fwrite script, that is fine, but to describe the whole thing, i need a script that will check numbers.txt, then use that number in a url (for posting a reply on a dedicated forum) so when a user presses post, it uses that url, instead of the same one. so after it gets the number, that number must be deleted from numbers.txt then replaced with 1 number higher.
So i guess it would go like this:
The url will have a php script, but i am not sure which one, i am guessing $_get that will retrieve a temporary number from numbers.txt and use that in a url.
Then when they hit post/submit, a script will erase numbers.txt and add a number that was 1 higher than the previous one.
I either need a full script or just some guidance. =)
Or another option is almost the same thing, but a script will check the database (i am not sure, but i think the post count would be there) for the post count, add one to it, and insert that temporarily into the url. i am not sure how possible that would be. but it would be nice not to upload another forum.
So this way would entitle:
A script within the url that will temporarily insert the post count plus one so the post is valid. (by post count, i mean the number of topics created). that pretty much sums up what would be needed. although i am not sure it is possible seeing as it would need to contact the database and find the total number of topics.
If it is any help, i use smf. i can also allow anyone who can help to use an administrator account on the forum to look at server information and stuff.


I am just interested if you have done or solved this problem because noone of you two haven't wrote anything after.

If you have solved this problem I will be glad to help you also.

 

 

 


Reply

robocz033
i am currently working on it with alex and ghostrider

Reply

slushpuppy
If your reading from a text file and wish to replace the current number with a number higher than it, use file(). Upon saving the results to an array, you can use array_map or other methods to increase that number. Following that, fopen(FILE NAME,w) will erase the contents and you can insert the new value into the file with fwrite.
Links
http://sg.php.net/manual/en/function.fopen.php

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : things php fread fwrite

  1. Php Chat With These Things - Need help with a PHP chat. (3)
  2. Sum - Adding things (11)
    I have this tiny problem, that is I have a whole list of vairables, 25 infact, and I'm trying to
    add them, and store this result in another variable. The problem when I try to call that variable
    the resulting page justs leaves a blank spot, and the IF array that I have won't change, it just
    goes for the first choice. Is this wrong? CODE
    $var1+$var2+..........$var24+$var25 = $vartotal; bearing in mind that
    there is more in the middle I just didn't feel like typing it!...



Looking for things, php, fread, fwrite,

Searching Video's for things, php, fread, fwrite,
advertisement



A Few Things [php Fread, Fwrite]



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE