Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,377 members, 7,808,342 topics. Date: Thursday, 25 April 2024 at 10:37 AM

I Need Help With A PHP Script - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Need Help With A PHP Script (3758 Views)

HELP - Installing A PHP Script On My Website Using GITHUB / What Is The Average Salary Of A Php Programmer In Lagos / Can Obfuscated Php Script Be Decoded? (2) (3) (4)

(1) (2) (Reply) (Go Down)

I Need Help With A PHP Script by pojutime(m): 5:45pm On Feb 04, 2006
Hi Y'all,

I work as a web developer for a not-for-profit. I intend to introduce a feature on the website which I need assistance for. have a folder containing several text files. There is a link on my homepage and If a user clicks on the link, it should display the content of a text file on a pop-up. Sounds easy, but here's the catch. The text files should be displayed just once i.e. if a text file is displayed today, in 24hrs time, when I click the link, it should display the content of the next file in the new window. Please note that this is not a "Quote of the day" application, it is very different. Those involve randomizing but this is somewhat different.

Seun and the other nairalanf gurus should please help me out. I'll appreciate it greatly.

Cheers.
Re: I Need Help With A PHP Script by Seun(m): 12:48am On Feb 05, 2006
What you need to know in PHP:
- How to obtain a list of files in a certain directory and sort them alphabetically or based on their last modified time.
- How to store the contents of a variable "filename" in a permanent cookie and retrieve it later.
- How to determine the next file to display from the filename in the cookie and alphabetical list of the text files.

Good luck!

1 Like

Re: I Need Help With A PHP Script by pojutime(m): 9:43am On Feb 05, 2006
Thanx Seun,

But i need the code. Thats why I've cried out for help. Hope to get a favourable response hereafter.

Cheers
Re: I Need Help With A PHP Script by joftech(m): 11:22am On Feb 05, 2006
can you provide the link to your homepage so i can know what you have already.

I don't understand your question mybe that will help me a lil bit.
Re: I Need Help With A PHP Script by pojutime(m): 11:41am On Feb 05, 2006
Thanx,

I havent created the link yet, i only spoke in futuristic tense. What I have in mind is a daily devotional kind of application. It changes automatically in sequence(not randomnly) after 24Hrs. The content of each devotional (text) files are dusplayed in a pop-up window displayed when one clicks the link.

Hope this explains better. Thnaks once again.

Cheers

1 Like

Re: I Need Help With A PHP Script by joftech(m): 12:55pm On Feb 05, 2006
Is it a must that it must display in a pop-up window? How about a part of the site.
Re: I Need Help With A PHP Script by oasis: 5:56pm On Feb 05, 2006
This thing would be a breeze if you stored your text in a db.  But, here's some help nevertheless..

Every one of those files has a unique filename, based on the path.
Therefore, store the filenames in a db, or a flat file with the date of last view next to it.

I have a similar feature on my website where each day somebody logs in, he/she earns 1 point within a 24 hour period.  If the user logs in twice within 24 hours, some date comparison is done, and no point is given the second time.

If you want a new file displayed when someone has seen the first file, then you need a sequential naming scheme for your files.  E.g. file1, file2, file3. That way you can call file2 if file1 has been seen.

To find out if it's been 24 hours since last click, you can issue a query like this:

$query = "SELECT (TO_DAYS(CURRENT_DATE)-TO_DAYS(lastviewdate)) ";
$query .= "as due FROM userstats WHERE username='$username' && filename='.....' ";

$row = mysql_fetch_object($result);

if($row->due>1) { // it's been more than a day since last view

   use your file functions here: fopen(), fread(), etc
   See http://us2.php.net/fopen, http://ffa.oasisoflove.com/fopen.html
}
else { // last view was less than 24 hours ago.

   show next file in the sequence...
}

Of course, each time a user views a file, you have to issue the query:

UPDATE userstats, SET lastviewdate=now() WHERE ...

The above is just a sketch to get you thinking.  You must provide some code if you want specific help.
Re: I Need Help With A PHP Script by Ralex(m): 6:32pm On Feb 05, 2006
There are so many ways to solve this problem buti think Oasis is right, employing a db is smart for what u have on mind. Follow oasis advice, name d file sequentially (1,2,3 ... e.t.c) when say the first click is made let d script read a file or database that holds the present record say file 1, increment it and overwite the iniatial record. when u get to the end just rotate he has provided scripts as well
Re: I Need Help With A PHP Script by sbucareer(f): 7:32pm On Feb 05, 2006
Come on guys, gosh!! this is file and directory manipulations.  Why DB?  DB would be very wrong for this project.  Read the requirements above it says file, time, access!

Well, you can implement this on DB and let me know how you got on.  Database application naturally suffer for connection problems.  Many advances has be introduced to alleviate DB access i.e datapool etc.  DB is good to store data for later manipulation.  But if I am correct the requirement of this project has the data store on a file (pdf), why re-store already stored data?

My solution if you need it is, the fact that you are implementing this on PHP gives me little avenue to help.  If it was in Java this is where JNDI comes in.  Using PHP I would advice using XML/XHTML with DOM

Describe all your data in your XML schema and write a good XML template to describe your application use XHTML to render your result and perhaps write a little PHP to synchronise with time, that is it.
Re: I Need Help With A PHP Script by oasis: 6:28am On Feb 06, 2006
Database application naturally suffer for connection problems.

c'mon sbucareer, aren't you being a bit melodramatic here?

Db connection is not a problem at all unless you're google that gets 500 million hits per day.

Look at the following:

I issued this query:

SELECT * FROM `replies` LIMIT 0 , 50

And here's the answer I received:

Showing rows 0 - 49 (42832 total, Query took 0.0024 sec)

How long did that query take, including the connection you're worried about?
Re: I Need Help With A PHP Script by Seun(m): 6:37am On Feb 06, 2006
You might want to offer money if you want working code and not mere explanations. It's fun to give explanation but not much fun to write and debug programs wink
Re: I Need Help With A PHP Script by sbucareer(f): 2:07pm On Feb 06, 2006
@oasis, sorry if I am being histronic, but the requirement would not digest well with DB, in my opinion at least. Yea! can you educate me on what u meant by


SELECT * FROM `replies` LIMIT 0 , 50

And here's the answer I received:

Showing rows 0 - 49 (42832 total, Query took 0.0024 sec)


Sorry, you totally lost me there? Could you explain more on this? Coud you also tell us how you come about google using DB to store all their Web-Map i.e websites?
Re: I Need Help With A PHP Script by disney(f): 2:59pm On Feb 06, 2006
Don't understand "Php script".
Re: I Need Help With A PHP Script by sbucareer(f): 3:06pm On Feb 06, 2006
@disney what language in programming are u into, if any?
Re: I Need Help With A PHP Script by pojutime(m): 3:22pm On Feb 06, 2006
Hi Y'all,

@Seun
I thought the forum was there to enable us share ideas and help each other. Afterall I didnt pay to register. Why ask me for money now when I need a few lines of code to complete a task.

@Others
I chose php for the task because i felt it'll be quite easy to overcome. I'm also learning it currently. Its not that I particularly have an obsession about it.
Its also okay if the link opens into a normal windoe and not a pop-up. Any of the 2 methods will suffice. Thanks.
Re: I Need Help With A PHP Script by oasis: 4:45pm On Feb 06, 2006
@oasis, sorry if I am being histronic, but the requirement would not digest well with DB, in my opinion at least. 

Yes, that's you opinion, but you're wrong.


Yea! can you educate me on what u meant by

SELECT * FROM `replies` LIMIT 0 , 50  And here's the answer I received:Showing rows 0 - 49 (42832 total, Query took 0.0024 sec)?

No pun intended, but If you don't understand the above query, then you shouldn't be taking part in any db-related discussion, let alone argue against its use.

Basically, the above query shows that I pulled 50 records from a database containing 42,832 records, and the result was returned in 0.0024 seconds. 

The fact that it took such minuscule amount of time demonstrates that the connection time is not a problem as you claimed.


Could you explain more on this?  Coud you also tell us how you come about google using DB to store all their Web-Map i.e websites?

I can't tell you, because I don't know the answer.  However, by deductive logic, I can say that the map data would be almost impossible to manipulate without a database.

You don't appear to know much about databases, am I correct?
Re: I Need Help With A PHP Script by oasis: 4:51pm On Feb 06, 2006
I thought the forum was there to enable us share ideas and help each other. Afterall I didnt pay to register. Why ask me for money now when I need a few lines of code to complete a task.

Listen buddy, in the world of programming, it's unfair to ask somebody to write you a code.  The standard practice would be for you to write the code yourself, then ask somebody to help debug it.

If you don't know how to proceed on an idea, then rather than ask for the code, ask for ideas instead.  Those ideas you get would help you develop critical thinking skills of turning thought into php code.  After all, you do want to learn don't you?
Re: I Need Help With A PHP Script by sbucareer(f): 8:56pm On Feb 06, 2006
Don't be naive Mr Oasis, the primary prerequisite for any computer Science Student is DB.  DB is NOT the issue here, I DB on oracle 10g everyday.  I don't use your sort of script language, which is still beginners script.  I use PL/SQL where you write SQL queries like you are programming Java.

I understand quite well that your script is trying to do at least.  The problem I had was that where do you run it?  On google or DB, which was relating to getting some page after some milliseconds. 

Anyway sha, I really do not know why I am arguing with you.

Now, Mr man you know DB and don't know your Network.  You'd thought when you were taught network at school, that it was for Network Administrator.  Naah!!

Let me tell you.  On a typical network backbone you have fiber/10000Base -5T, what does this mean?  It means you can transmit 10000 electrical impulse/+5volts -5volts across a copper or fiber class over 5000meters long.

Now your dial-up to the your ISP at the most 10Base -2T. 10 electrical impulse (bits) over a twisted pair of 200 meters long before attenuation.

If your DB is in Hong Kong and you are at Nigeria.  You have to consider latency (length of electrical impulse/wave frequency) and how many packet(s) would be lost and require repetition.

Furthermore, the DB would have some way to handle all the request in some sort of orderly way, putting you request even more delays.

To actually find the time it takes to access a DB on a massive scale you need a logarithm to some base. To find your connection speed to your DB you'd need this equation.

dB = 10 log10 (Pfinal/Pref)

db = decibels
log = logarithm
Pfinal = is the delivered power measured in watts.
Pref =  is the original power measured in watts

This equation is just for you to get you network connections and speed incheck.  After that you will read your DB manual to get more information on time access.  Depend how good u are on query, you can get good response.  If you write sloppy scripts you gets sloppy response.

Please don't compare your localhost DB speed to a networked DB running at a remote place.
Re: I Need Help With A PHP Script by oasis: 9:42pm On Feb 06, 2006
Nigerians!

What is wrong with you guys that you just love to argue unnecessarily?

This is one of the reasons Nigeria is backward.  Everybody is always claiming to know everything, and nobody can tell them jack.  A typical technician abroad may know more than a PhD holder in Nigeria.  Why?  Because Nigerians love to waste time arguing about theories, even when practical facts are staring them in the face.  There is such a thing as pragmatism.

To answer your question about how I got the 0.0024 seconds value, I used phpMyAdmin.
Re: I Need Help With A PHP Script by sbucareer(f): 10:11pm On Feb 06, 2006
"oasis":
A typical technician abroad may know more than a PhD holder in Nigeria.  Why?

At least a typical technician abroad will NOT do expo or bribe lecturers to get their certification.


That is why loverBwoy said Nigerian graduates are half baked
Re: I Need Help With A PHP Script by joftech(m): 10:51pm On Feb 06, 2006
I understand quite well that your script is trying to do at least. The problem I had was that where do you run it? On google or DB, which was relating to getting some page after some milliseconds.

Are you telling us you have never heard of MySQL.
Re: I Need Help With A PHP Script by sbucareer(f): 11:00pm On Feb 06, 2006
@joftech, you misunderstood me.  I understands his script and what it does. the table replies is on localhost DB (mysql) and he is claiming fast response time of 0-50 cartesian product at 0.0024 seconds.  This would not be the same on networked or remote DB which was based on the argument of developing the title of this thread.

Everyone knows what is MYSQL
Re: I Need Help With A PHP Script by joftech(m): 11:06pm On Feb 06, 2006
Well i understand what you are saying about the latency issue, but the DB approach should be able to solve the problem at hand considering the fact that we are talking about microseconds here.

Here i get 700-1000 ms latency on my VSAT link, still am able to communicate with people around the world. The latency issue is mostly applicable in mission critical scenerios and mostly voice/video related stuffs.

A DB approach will provide the much needed solution to what that guy need. Afterall we are not talking about waiting for millions of entries.
Re: I Need Help With A PHP Script by sbucareer(f): 11:10pm On Feb 06, 2006
Thank you joftech your comment was eloquent and it is well noted.  I need more of this sort, a constructive argument.  Thanks joftech
Re: I Need Help With A PHP Script by pojutime(m): 12:37pm On Feb 08, 2006
sad sad sad

The above descibes how I feel. I thought I could get a solution to my problem from Nigerians, little did i know that I'd start a thread of argument not necessarily related to my plight. Anyways since the moderator has spoken, I guess I'll find my solution in a proper php forum, most likely a foreign one.

SBUCAREER, joftech and other respondents, thanks anyway.

Cheers
Re: I Need Help With A PHP Script by sbucareer(f): 1:26pm On Feb 08, 2006
@pojutime, please can you provide more elaborate description of your problem.  Maybe I did not understand it very well.  The hardest thing for business analyst is requirement elicitation.  Many software development fail today because of poor customer/client agreed requirements.

Please, tell me if you would not mind this solution in java.  I could provide complete solution for you.  But it will take some time as I am busy.
Re: I Need Help With A PHP Script by oasis: 3:35pm On Feb 08, 2006
The above descibes how I feel. I thought I could get a solution to my problem from Nigerians, little did i know that I'd start a thread of argument not necessarily related to my plight. Anyways since the moderator has spoken, I guess I'll find my solution in a proper php forum, most likely a foreign one.

SBUCAREER, joftech and other respondents, thanks anyway.

Cheers

You're crying like a baby. Go learn how to code. Nobody is beholden to you here. We're just trying to help.

I would like to see any forum on the net that'd provide you with full code based on your lukewarm explanation of the problem. We've given you good ideas, use them to develop your coding skills. You'd never learn otherwise.

If you take our ideas and start coding, we would then be able to help you further.
Re: I Need Help With A PHP Script by pojutime(m): 5:06pm On Feb 08, 2006
Thanks,
But the insult is uncalled for. Who's crying? sbucareer, I'll get back to you soon, maybe I'll even mail the mail the objectives to you. I'll serach out php forums who give real custom code, real time, dont ask for money and don't mind where you reside.

Cheers.
Re: I Need Help With A PHP Script by oasis: 6:58pm On Feb 08, 2006
Thanks,
But the insult is uncalled for. Who's crying? sbucareer, I'll get back to you soon, maybe I'll even mail the mail the objectives to you. I'll serach out php forums who give real custom code, real time, don't ask for money and don't mind where you reside.

Cheers.

You see, you're doing it again. You're whinning because you can't get your way. Trust me, I'm more help to you than anybody who would hand you a code. Teach a man to fish...

What php forums give custom code without money? There are free php scripts everywhere, but those aren't custom code.
Re: I Need Help With A PHP Script by joftech(m): 7:23pm On Feb 08, 2006
Thanks,
But the insult is uncalled for. Who's crying? sbucareer, I'll get back to you soon, maybe I'll even mail the mail the objectives to you. I'll serach out php forums who give real custom code, real time, don't ask for money and don't mind where you reside.

Cheers.

Poju, you must be the typical Naija graduate. So you want someone to spend his time for you on a code in order to save your ass from being sacked, LOL. You can't even define your requirement(s) clearly talkless of doing the coding yourself.

No forum will give you a customised code when you don't know what you want. At least in here we have given you enough pointers that can get you started if you are bent on finishing that project and learning something new.

Poju, you are in the real world, not where you "lift" essays from texbooks to exam sheets.
Re: I Need Help With A PHP Script by alexis(m): 1:35am On Feb 28, 2006
Guys - easy on Poju. Poju - we are all busy guys, if you want a code to generate random quotes from text files that is not a hard thing to code in php. I saw one of the guys provided you a template, I think that is straight forward and you can use it but if you want us to code the app and give it to you, you will not be learning as you should.

If you really need the code and you will use it for a church or educational institution and place book marks on the site you will deploy the code back to my home page, I will create the script for you. Fair enough?
Re: I Need Help With A PHP Script by sbucareer(f): 1:21pm On Feb 28, 2006
alexis you are a good [img]http://pro.imagehost.biz/ims/pictes/209210.gif[/img]

(1) (2) (Reply)

Programming Challenge(python,java,vb,.net: Etc) / What's Your Favorite Text Editor/ Or IDE? / Facebook Database Schema (take A Look *parental Advisory*)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 86
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.