I am making a site(project). its an education portal, which consists of various pages like Notes(containing list of available notes), Papers etc..
All these pages are simple html pages with table tag to display list of available contents. Now the problem is that I want to use PHP pages for admin login, where the admin enters the Name and description of the new notes and it is automatically added to the HTML table tags. ( this is because i dont want the tables content to be loaded from a database each time a user wants to see the available projects)
Plzz help (No need to write and post code for this, just give me the basic idea how can it be done.. )
- Make a form in the admin page and have a text area.
- Read the file (html or any files) with fread function and show the content in that text area.
- Then admin will make changes and submit the page/form and write the changed contents to the same file with fwrite function.
Hope you are well familiar with the basic PHP programming and you can do it yourself.
I wouldn't have the PHP edit the HTML directly. You could use SQLite to store the data (to avoid using an extra server), then generate the HTML from that data and cache it so you don't need to regenerate the page every time.
Thnkx, but isnt there a way to edit the page directly. As i said before, what i had in mind was that in the admin page i would just add the name and short description of the project and the code would translate it into <td> code(this part i can do myself) and add it to the table tag in the html file automatically.
Basically, isnt there a way to mark a specific location in a html file, which can be used to add any code via php
The way i see it if i edit the html page directly it would save lots of access time. My priority is to keep the time as low as possible, thats why i want to use html pages and not connect with a DB. Why do u thinking editing html directly is not gud??
Writing to a particular place in the file is bit of tricky work as far as i know. Since you cannot move the file pointer to the particular location. It will be at the end of the file if you are editing the file or it will empty the file. The technique will depend on how you open the file. As you said before i just gave a simple steps and functions that may work for you to read and write the contents to a file. I hope now you can do that reading whole html file and write it to the same file.
But, i will still recommend you to go for database system for such things it will really make your life easier and safe too. It will not slow down your site.
Rajug has the right idea, though the reason I suggested SQLite is because you don't really have to connect to a database. It's stored as a local file, not a table on a server, but works like MySQL for reading and writing values.
Ohk.. so u mean i should make all pages as PHP and get the table data from the DB. Like a forum thread, Right??
Indeed, these forums also work in that way with database. PHP does saving the contents to the database and retrieving them to the user back in the browser from database. So create a database and have at least a table with couple of fields as per your requirement (id, name, description) and save the name and the description to those respective fields. Now when you retrieve them back to the browser then you must construct the table->tr->td or whatever you have in the design. This way you can manage the things easily. Hope you understand and can do the things yourself.