![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
what's the best way to do this?
I have one page where you a user can enter into fields items they would like to display as bulletins. Then I want them to display on the index page. I'm not sure which is going to be the best way of doing it? Can you point me in the right direction?
Just a hint would be ok. I still want to write it myself. So at least I get some good practice there. ![]()
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
use a database or a text file.
the database route is far supreme though. check out a db system like mysql or postgresql. that should get you started in the right direction.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
at first I was going to do that, insert into a table and then formt he index page query and echo the tables contents, but I don't want it to keep adding I only want 10 bulletins to appear and for those to be edited by the same screen that input them.
Maybe i'm gong about it the wrong way. I also thought if I could insert each of the fields into an array that and then print them on the index page. Will this work? and if so How do I call the array from the index page?
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 4
![]() |
You can limit to the number of results from the table by putting LIMIT 10 in your SQL query.
ex. SELECT * FROM 'my_table' LIMIT 10 (Someone correct me if that is wrong.) You can ensure that they are newest 10 by having a date field and modifiing the clause to get only the newest 10.
__________________
_______________________________ BlazingWolf |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Apr 2005
Posts: 9
Rep Power: 0
![]() |
It depends, you haven't really given enough information about what you want to do...
If you want this information to be availiable to anyone who visits the index page then yes you will need to store it somewhere. But if its only 10 things then I dont think the trouble of setting up an MySQL database and querying it is really worth it.. I dont normally use text files for anything big but for something of that scale it is far more appropriate. Another possiblilty is storing them in server memory as global variables but *cough* I didnt make that suggestion because global varibles are evil and unsafe. If you only wanted to temporarily display them for the user that posted them you wouldnt even need to store them, you would just need to output them (why even bother loading them into an array when they have to get sent seperately by the form) you could output them straight from the temporary variables (i.e $_POST[]) straight to the page.
__________________
www.ice52.co.uk |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
Thanks for your advice everyone. Here's some more information that might be helpful.
It's for a database I'm making. It's got to be permanet until changed by a user. The Home page of the database will have a section where bulletins can be posted for other employees to see. I have made one page where you can edit the bulletins list. via 10 different textboxes. I want the to be able to go back to this page and edit/update these from the same page. So what do you think? What will I need to do this?
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Apr 2005
Posts: 9
Rep Power: 0
![]() |
Yep, sounds like a database job to me.
You just need to make a table in the database to store all the info about the bulletins (id, message, poster?), MySQL is a favourite for databases you will need that as well as php (obviously). Then check out the MySQL functions on the php website, it should be pretty obvious what to do with those. So you post the information to a page (possibly the index page) then you include a php function in this page to insert this info into the database, and another to query the database when the page is loaded up. have I missed anything?
__________________
www.ice52.co.uk |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
That's about right.
So I limit he table to 10. inserting the information into the table. then query the info back out. Pretty simple except how will I edit them? (from the page I inserted them from, which is a separate page from the index page)
__________________
Lorem ipsum dolor sit amet... |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Apr 2005
Posts: 9
Rep Power: 0
![]() |
ahh, well there you have to use the SQL command 'UPDATE', thats where the id comes in, you will need some way of getting the id to the page and being able to submit it back to the server, to show which one you want to edit. Since the id is unique it makes the record easy to identify and change.
The way I usually do it is via a link with a query string (eg href="myeditpage.php?id=2") but in this case you might want to send the edited info along with the id, so i suggest a form with a hidden input... I dont know... do you want to be able to edit using the original as a template, because in that case you would need a textarea or something for every submission (so 10 then ) and each would probably need to be a seperate form with its own submit button... Thats just an idea though.Hope I wasnt too confusing but yeah you are right about the steps... except you might want to run a query on the DB when you add a new record that deletes any records after the 10th (you dont want those extra bulletins clogging up your db... unless you wanted to archive them of course)
__________________
www.ice52.co.uk |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Feb 2005
Posts: 74
Rep Power: 4
![]() |
I appreciate your help. I guess I'll just start working through it and see how it goes.
Maybe I'll save that part of the DB for last. ![]()
__________________
Lorem ipsum dolor sit amet... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|