 |
|
|
07-05-2005, 08:36 AM
|
Online Mag
|
Posts: 82
Location: Bistrita RO
|
Hi. I'm quite new to PHP and MySQL and XML, and I have to do this dynamic site. Basically, it's the online archive of a magazine.
I'm thinking this should be:
- a XML file for each article, somehow like this:
Code:
<title> Article Title </title>
<content>
<section>
<sect_title> Section Title </sect_title>
<sect_content> Section Content </sect_content>
</section>
<section>
<sect_title> Section Title </sect_title>
<sect_content> Section Content </sect_content>
</section>
<section>
<sect_title> Section Title </sect_title>
<sect_content> Section Content </sect_content>
</section>
</content>
and then a PHP script to insert this into a page template (this is the difficult part).
Am I thinking it all wrong here? Can you help me a bit? Any piece of info would be great.
|
|
|
|
07-06-2005, 02:13 PM
|
|
Posts: 174
Location: Nigeria/Lagos
|
I guess u gonna use PHP and MySQL
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.
Please login or register to view this content. Registration is FREE
|
|
|
|
07-06-2005, 02:28 PM
|
|
Posts: 116
|
well u can use the php include() function. but i dont really know xml, so it mite not work.
|
|
|
|
07-06-2005, 03:26 PM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
You can use the PHP include() function quite easily, but it might be a lot easier for you to drop the idea of XML and use a dynamic HTML template instead. You can use MySQL to handle the articles etc., or you can simply hold these as txt or pgp files on the server - this of course depends on the levels of security you want over the content, and, of course, your proficiency with MySQL.
The data you include in your articles can simply be arranged in a txt file as a new line separated array - line one being the title and line two the content. It is then a simple matter to use the PHP include() function is the data is stored as a PHP file, of the file_get_contents() function if it is stored as a txt file.
You can then easily apply a set syle for each section using normal HTML and CSS.
I hope this helps and does not pose more questions than answers.
|
|
|
|
07-07-2005, 08:48 AM
|
|
Posts: 82
Location: Bistrita RO
|
Thanks for your replies. Styling won't be a problem. It's how to get different content in a template using php & mysql i'm not too crazy about.
I think i could get the php part to work using the include() function (need to look that up :P).
The structure of the articles is basically:
- the main title
- introduction
- section titles with a few paragraphs each
- some pictures on the way
Is it ok to make folders for the years and the months and then create separately all the articles in html (without menus and other elements) and then create a table in MySQL with the path to the different files? (and then use something like href="article.php?year=1999&issue=10")..
|
|
|
|
07-07-2005, 06:25 PM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
The system you suggest for storing the articles is fine as you can take the 'year' as the name of the folder and 'issue' as the ... well, name of the issue. Assuming that you have stored the issues in csv .txt files (though you could call them anything you like!), you would get something like:
PHP Code:
<?php
$year = $_GET['year'];
$issue = $_GET['issue'];
$pathname = $year."/".$issue.".txt";
$handle = fopen($pathname, "rb");
if (flock($handle, LOCK_EX)) {
$contents = file_get_contents($pathname);
flock($handle, LOCK_UN);
}
fclose($handle);
$data = explode(",", $contents);
?>
The contents of the relevant issue are now in the $data array and can be output as a how you please.
However, you can also store the issues as php files by inserting the csv into the array and saving that as the file - for example:
PHP Code:
<?php
$data = array (
"Item1","Item2","Item3"
);
?>
Now your code to read the contents of the issue would be:
PHP Code:
<?php
$year = $_GET['year'];
$issue = $_GET['issue'];
$pathname = $year."/".$issue.".txt";
include ($pathname);
?>
I hope that's clear enough and helps. I use a similar system for my News on my site (top one of the two in my sig). The code behind that page is:
Code:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>OP4 - News</title>
<link rel="stylesheet" type="text/css" href="scripts/op4.css" title="standard">
</head>
<body class="body">
<?
include "includes/popup_head.php";
include "includes/news_feed.php";
?>
OnlyPlace4 News</div>
<?php
$n=0;
while ($n < $news_loop) {
echo "<div align='center'><h1>$news[$n]</h></div>";
$n++;
echo "<p class='xsmall'><b>$news[$n]</b><hr align='left' width='100'>";
$n++;
echo "$news[$n]";
$n++;
}
?>
<hr width='50%'><br></td></tr>
<? include "includes/popup_foot.php"; ?>
</body>
</html>
I hope that's clear enough for you. If not, give me a shout 
|
|
|
|
07-08-2005, 03:12 AM
|
|
Posts: 82
Location: Bistrita RO
|
wow, ok, i need to chew this up a bit...  thank you very much for your time.
I forgot to say in the last post... every issue has several articles.. so i should be doing something like article.php?year=1999&issue=10&art=2
I just realised i don't really need a database for that... i can just have something like:
PHP Code:
$path=$year."/".$issue."/".$art.".txt";
include($path);
and keep every article in html formatting (without the <head> tag, only the actual content).
the page would be:
Code:
<html>
<head>...</head>
<body>
<div id="header"> here comes the header</div>
<div id="menu">here is the menu</div>
<div id="content"> <?php /* code above */ ?></div>
<div id="footer">footer</div>
</body>
</html>
And here comes the problem... if i had images in the article, how would i insert them in the article? (the path changes when i grab the file from year/issue folder and put it in the article.php, which will be in the root folder). Should I have all the images from the articles in one big folder and then link them like: images/0001.jpg ?
Last edited by danburzo; 07-08-2005 at 03:25 AM..
|
|
|
|
07-08-2005, 06:14 AM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
Nope, you can follow the same technique and have the articles and images in the same folder as, when you include a file, the relative paths within that file become those of the page served and not the directory in which they are saved.
Lets consider you have a directory structure that looks like:
Code:
/root
images/
articles/
1999/
01/
02/
etc.....
The root to images in the folder articles/1999/02 is, of course, articles/1999/02 from the root. If you are serving the page that displays the articles from the root then this is the path it will need, and that is, of course, the path you have parsed in the php. Therefore, your image placeholder will look something like:
PHP Code:
<? echo "<img src='$path_image1.jpg'> ?>
It's all a matter of thinking a little laterally. If the page serving the article is located in the root folder of your site, then all paths within that page, irrespective of where they are physically stored on your server, will be from the root.
I hope that's clear enough.
|
|
|
|
07-08-2005, 06:42 AM
|
|
Posts: 82
Location: Bistrita RO
|
I got it!  Thank you. You've helped me enormously.

|
|
|
|
07-08-2005, 06:49 AM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
No problemo ... glad I could help. Good luck with the mag. 
|
|
|
|
07-08-2005, 06:56 AM
|
|
Posts: 82
Location: Bistrita RO
|
ok, i've stumbled upon another problem. how do i insert the article title in the <title> tag of my article.php file?
|
|
|
|
07-08-2005, 07:45 AM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
Two ways to do this.
1. You can use the $path info if the article does not have a specific title. As the page the delivers the article will be in php anyway you simply have the <title></title> as below:
PHP Code:
<? echo "<title>$year :: Issue Number $issue :: $art</title>"; ?>
2. If you want the article to have a specific title, let's say "Wigdets are great!", you would name the article file "widgets_are_great!.txt" and then strip off the ".txt", remove the "_", turn the first letter into an upper case one, and then use that. Not as hard as it sounds:
Quote:
<?php
$year = $_GET['year'];
$issue = $_GET['issue'];
$art = $_get['art'];
$art_len = strlen($art);
$title = substr($art, 0, $art_len-4);
$title = ucfirst(str_replace("_", " ", $title));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<? echo "<title>$title</title>"; ?>
</head>
<body>
Rest of your page ......
</body>
</html>
|
If you want ever first letter of each word as Upper Case then change the ucfirst( to ucwords( .... it's as easy as that!
Hope that works for you.
PS: Don't forget that if you use file names in this way your associated images will also need to have this as part of their filename, ie: widgets_are_great!_image1.jpg. If this is too cumbersome add a four layer to the parse - &img= - and use this to give related images a unique associative identifier to the relevant article.
|
|
|
|
07-08-2005, 09:42 AM
|
|
Posts: 82
Location: Bistrita RO
|
How about i create a titles.php file in every issue's folder, containing:
PHP Code:
$title_array = array ("Title 1", "Title 2", ... ,"Title n");
and then the code in my page would be:
PHP Code:
<?php $year=$_GET['year'];
$issue=$_GET['issue'];
$art=$_GET['art'];
$titlepath=$year."/".$issue."/titles.php";
include($titlepath);?>
<html>
<head>
<title>&title_array[&art+1]</title>
</head>
<body>...</body>
</html>
I have a few questions:
1. When i get the article number with $art=$_GET['art'], is $art an integer or need i to use the Integer.parseInt() function?
2. For arrays, does the count start from 0 or 1 (element index)?
|
|
|
|
|
« Reply to Online Mag
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|