Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-16-2004, 04:34 PM   #1 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
shared thinking

okay on my site, because for reasons that dont need to be stated, im not always at a computer with a ftp program everyother weeked or so, so im in the process of setting up a admin page. it has basic controls on it, i log in, from there i can post a news entry, edit the existing ones, post a new article or edit the existing ones and thier comments. i was wondering how you guys would set up the edit news part, all my news is in one file with special dividing chracters, and so far this is working good, when i go to edit it, it puts all the titles and entry in form boxes all in the same form. then i have the page evulate which buttin was pressed for the corresponding entry and edit or delete that entry. how would some of you guys set your system up, and anyone have some questions about how exactly i got parts to work, or any criticle things about my system.
falsepride is offline   Reply With Quote
Old 11-16-2004, 05:10 PM   #2 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
It sounds like you would need to load each news article into an array, fairly straight forward. But wouldn't it be easier to use a MySQL database?
__________________
Current Project
Redline is offline   Reply With Quote
Old 11-16-2004, 05:15 PM   #3 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
never learned MySQL, so far i've been able to do everything i've ever wanted in php, and simple php functions too. it may not be the expert way to do things, but it works so far. if it werent for variable variables i wouldnt beable to have set up what i have so far, so if i can do everything in php whether it be harder ill stick to it for now, maybe when im done ill try and jump into mysql.
falsepride is offline   Reply With Quote
Old 11-16-2004, 05:21 PM   #4 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
A non-flat database would be alot easier! Falsepride you don't half have to do things the long way around!

Here's how I would do it...

I'd have 2 tables in my db. The first is 'news' with 5 fields:
1 nID (not auto-inc but the news saving code would count the rows in the news table and add 1 to it so that the same number can be used in the second table, 'comments')
2 title
3 body
4 author
5 when

Now depending on if I have a secondary author that doesn't have complete permissions, I'd have an extra field titled 'verify' which would be either 0 for not being shown at all or 'deleted', a 1 for displaying it or a 3 for an article submitted by one of my news reporters that needs an admin's verification.

The second table would be titled 'comments' and would have 5 fields much like the news table:
1 cID (this would be what the nID is as explained in table 1)
2 uc (standing for unique comment. This id would be to distinguish between the other comments for each news item. Would also be used to dynamically populate anchor links so that people can specificall;y hot link a URL directly to this comment. This technique is used alot in blog systems with a name such as 'link to this entry')
3 body
4 author
5 when

The page with the news on would be a loop that would go through the news table and pull the news off it. In the bottom corner would be a dynamically created figure from the amount of comments for that news, '(6 comment/s)'.

As for editing the news, I'd have a session check in the code that check if the 'admin' is logged in. If he is then it will display the 'edit' and 'delete' links beside each news item. The URLs for these would have the url with a GET variable appended on which would be the nID as well as the variable action=edit. The page that loads up would take this nID, look it up in the db and populate the news edit fields with what they return.

When the save button is clicked, the news text would simply replace the news item in the database.

If the 'delete' link was clicked then the page that loads up would also have the same GET variable nID but the 'action' would be action=delete and it would ask you to confirm the deletion. When the 'Yes' is clicked then the same page would load with the same GET variable accept a new variable would be introduced confirm=1 and then the page would just either run the SQL DELETE code or just set the 'verify' to 0 as explained way up there ^^.


Now....it is half past 2 in the morning. I'm tired and feeling nasty so sorry if this made little sense but you should get the gist.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a

Last edited by DavH27; 11-16-2004 at 05:24 PM. Reason: 0 instead of 3
DavH27 is offline   Reply With Quote
Old 11-16-2004, 05:39 PM   #5 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
what you said made no sense to me at all, like i said i dont know mysql. nor have the time to at the moment. so far flat files are working perfectly and the amount of php coding im looking at isnt much. its straight and to the point no beating around the bush. but maybe when its not 2 in the morning in london you could try and explain what you just siad in smalled words with no abreviations, it would make it easy for me to understand. and since most of programing in my opinion is like algebra you have problems with multiple ways to solve it, everyone comes up with their own style of thinking. when your trying to explain your style to someone else, its most of the time best to go into extreme detail
falsepride is offline   Reply With Quote
Old 11-16-2004, 06:36 PM   #6 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Most of the design that DavH mentioned is pretty standard for a RDBMS-based setup. One table for the news block and separate tables for related data. Admin auth: dead-simple way is to stuff all your admin scripts in a separate directory and secure it via a .htaccess file. No, its not very flexible, etc.. etc.. ,but it sounds like you're the only one modifying news.

But yes, it was a quick response.


Quote:
when i go to edit it, it puts all the titles and entry in form boxes all in the same form.
I don't follow. Do you mean it loads all of your news into various form elements on one page so you can edit everything at one time? Could be quite a lump of data once you get some news built up.

Some kind of SQL DB might be a good option, but don't feel like you need to use one.

Some questions:
- What is the file format? eg: one news item per line with each element separated by a pipe, comma, etc..

What I would do is write the news to one entry per line separated by a pipe and have the edit function pass the line number of the news item.

So:
1 - List all news. List page generates a dynamic link to {a href="news_edit.php?id=<?=$line?>">edit{/a} (ignore curly braces)
As the script reads the data, line by line, increment $line so we have an identifier.

2 - Edit. Edit page will only edit one news item. Store the line number (passed by the display page) as a hidden variable in the form.

3 - Save. Upon posting the data the script will read the entire file into an array and only replace slice $line-1 (arrays starting at zero) with an imploded array of the posted data.

If you have more than one file and the data needs to be related, then its probably worth using a DB (mysql or even sqlite) and some row ID's for easy linking.

It might be worth checking out how other flatfile systems are doing it. Here's a quick search of freshmeat for php CMS systems that use a flat file for storage.


freshmeat search

http://freshmeat.net/projects/fancy/ - looks interesting

http://www.fusionphp.net/
^ flat file news script.

That make any sense?

-r
idx is offline   Reply With Quote
Old 11-16-2004, 06:53 PM   #7 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
After looking at fusionphp's news script, which is pretty slick, you might just be better off using theirs. That is unless you just want to create your own and have fun doing it.

-r
idx is offline   Reply With Quote
Old 11-17-2004, 11:03 AM   #8 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
id more into doing everything yourself when it comes to coding. im only setting up a site for practice, no real rhyme or reason. and for my news getting bulkly it won't. basically its smalle entries about a new improvement to the site, or saying theres new pics or articles. at most the file will never be bigger than 1 meg.
falsepride is offline   Reply With Quote
Old 11-17-2004, 11:05 AM   #9 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
oh and yea the way im setting it up, i can edit all of the entries at once, just cuz i felt like having that option. most of my editing is probably gonna be spelling erros and what not
falsepride is offline   Reply With Quote
Old 11-17-2004, 11:36 AM   #10 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
if you have time to figure out and write a flat file news article application .. then you have time to learn how to use php with mysql.

PHP Code:
function addarticle($title,$article,$time){
  
$result mysql_query("insert into article (title,article,time) values('$title','$article','$time')");
}

function 
editarticle($articleid,$title,$article){
  
$result mysql_query("update article set title='$title',article='$article' where articleid=$articleid");
}

function 
deletearticle($articleid){
  
$result mysql_query("delete from article where articleid=$articleid");
}

function 
printarticles($howmany){
  
$result mysql_query("select * from article order by time desc limit $howmany");
  while(
$row mysql_fetch_array($result)){
    echo 
"<b>".$row['title']."</b> ".$row['time']." <br>".$row['article']."<br><br>n";
  }

using file i/o functions, these functions would be much bigger, and you would have much less control over selecting and updating data.

just my $.02
__________________
Mike
sde is offline   Reply With Quote
Old 11-17-2004, 11:42 AM   #11 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
what the hell does msql_query do? all this makes no sense to me
falsepride is offline   Reply With Quote
Old 11-17-2004, 12:01 PM   #12 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
mysql query sends an SQL query to the database. SQL ( structured query language ) is a simple way to get the data you want.

here are some examples of useful queries. let's say i had a database of people.

// find all people who's first name starts with 'm'
select * from table where firstname like 'm%'

// find all people who's first name equals mike
select * from table where firstname = 'mike'

// find all people who's first names are mike or john
select * from table where firstname = 'mike' or firstname = 'john'

// delete all people from the database who's first name is mike
delete from table where firstname = 'mike'

// add a new person named john dough to the database
insert into table (firstname,lastname) values('john','dough')

let's say you had a 'lastvisited' field in your database which tracked the last time a user visited .. i could use the following query to get all users who visited this year

select * from table where YEAR(lastvisited)=YEAR(NOW())

you can keep going and get very advanced with sql also. it will allow you to seek out just about any specific data you want. for learning, just stick with simple SELECT, INSERT, UPDATE, and DELETE statements though. that is if you want to

once you do the mysql_query, it returns a set of results. if you do a select * then it will return all fields in the table you are querying. in our case, it would be the equivalent of returning a multidimensional array of people.

i probably didn't make this sound very simple, but once you start using it, you really see the power gained with not even that much of a learning curve.
__________________
Mike
sde is offline   Reply With Quote
Old 11-17-2004, 12:36 PM   #13 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
Oh andthe little kick you get it quite rewarding, too

I recently had my news on a .txt file and imported it into MySQL and it works great

The foirst time I started usign MySQL was with that benchmark database project and it has definately got good points

Ok the basic terms of using a MySQL database.

It's 100 times easier if you have access to your server's PHPMyAdmin. You can see what works and won't need to worry about having to code a table-creating script as well as that app will do it for you.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 11-17-2004, 12:40 PM   #14 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
Quote:
Originally Posted by DavH27
It's 100 times easier if you have access to your server's PHPMyAdmin.
if you have a database account ( dbname,username,password ) then you can just go download PHPMyAdmin and install it in your own directory. (if you don't have access to the 'servers' phpmyadmin ) You just need to put your db information in the config.inc.php file.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 10:54 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting