php - adding a news article auto creates page for it

Joined
12 Feb 2006
Posts
17,628
Location
Surrey
so i got the news thing all working brilliantly, really impressed with it, the only thing i don't like about it is that the articles don't get their own page as the way i view them is to show articles with a specific category which means that i get all the articles and not one by one.

At the moment the tables for the articles in the database are, id, title, author, category, post and date.

Im thinking of something along the lines of when i submit php will copy a page and then rename it to the id as its unique, and then have the page do some php (this is where i have no clue on) and have it check the file name and get the id number from that, then do a mysql query and select the article with id="filename"

Is this possible and how would i go about doing it?

thanks
 

I tried your code and made the changes but it didn't seem to work, it didn't like the } after the header part.

Conrad11 said:
What you have:
A page with all the articles on.

What you want:
Separate pages for each article?

It gets confusing when you start talking about filenames, are you looking to cache the pages or simply when you go to article.php?id=1 it will get the article with the ID = 1 from the database and display it on the page.

yeah sorry im finding it hard to put into words. What you think is correct, that at the moment i have pages that query the database for all articles that have a specific category and i want seperate pages for each article automatically made when the article is submitted.

So im thinking so say on the category page i selects all the articles with categroy, "house" and display the title which is a link to the article and the address is based on the id

for instance
Code:
include ('../services/mysql_connect.php');
$query = "SELECT * FROM table WHERE category = 'house' ORDER BY date DESC";
$result = @mysql_query($query);

if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

echo " <h3><a href="$row[id].php">$row[title]</h3><br/ >";

then on the page that is linked to it will check what the name of the file is which will be the id of the article, and then display whatever article is with that id:
Code:
include ('../services/mysql_connect.php');
$query = "SELECT * FROM table WHERE id= 'name of file???'";
$result = @mysql_query($query);

if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
<h3>$row[title]</h3><br />

<i>Posted on</i> $row[sd] <i>by <a ../login/userinfo.php?user=$row[author]\">$row[author]</a></i>

<br /><br />

$row[post])

<br /><br />

<i>Categories Posted in:</i> <a href=\"blog-view-$row[category].php\">$row[category]</a>

<br /><br />

hope that made some sense and not more confusion of what i need help with? the part the im lost with is getting the name of the file where is say "name of file???".

thanks again
 
Last edited:

still not working for me, telling me that exact same problem as the previous code.

ok i have tried rewording again what i want just incase its not clear.

So when i create an article, php will find a file, copy and then rename it to the id number, so for instance first article i add will create a file called 1.php.

1.php will then check what's its name, and then search for any article that has an id with the same name as the 1.php and display it.
 
sirlemonhead said:
Why are you messing with creating new files?

Just make a 'show_article.php' or some such named file, pass it the news item id and then display the single article using that file every time?

pass it the news item? you care to explain? i understand what your saying but no clue how to which is what this thread is for iirc.
 

hmm ok i see that would be much easier for update purposes but the code provided is still not working and i have no clue where i'd put the part to echo out; guessing after the following?:
//here you would create the html page in a the string $html_text.
 
Conrad11 said:
Lol...well you do actually have to put the code for creating the $html_txt string as that is project specific (different for every project), assuming you haven't already done that?

If you have then post what error message you are getting?

Parse error: syntax error, unexpected '}' in /home/mammal00/public_html/admammal/blog/cache.php on line 10

thats the error message i get. What no earth is the $html_txt string? would i something like the following?
Code:
<?
include ('../services/mysql_connect.php');
$query = "SELECT ' FROM table where id='?what woudl go in here?' ";
$result = @mysql_query($query);

if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {


echo "
</div>

<h3>$row[title]</h3><br />

<i>Posted on</i> $row[sd] <i>by <a href=\"..//login/userinfo.php?user=$row[author]\">$row[author]</a></i>

<br /><br />

$row[post])

<br /><br />

<i>Categories Posted in:</i> <a href=\"$row[category].php\">$row[category]</a>
 
marc2003 said:
try this?

you sexy monster, at first didn't work as the ids i was trying didn't have an article with them, so i got straight on here typed out a whole post, and bam i realised why it didn't work, tried and yippee out popped an article.

thanks so much for everyone who helped me with this problem.

Only last wish of mine is if someone could explain how the $id = intval($_GET['id']); works?

I understand that what going on but this intval bit is a lil confusing as im not entirely sure on how it does what it does. Like is it just a it of code that says ok now look at what page we are at and read the part after the ? and then the bit that says get id looks for id= and gets the number or seomthing?

thanks again.
 

ok did a quick read, so is the intvl just a security thing?

so how does the page know to read whats after the ? in the address bar?

say in the future i want to select all articles in category='home' and author='admin' how would i do this?

I'm guesig its relatively easy just don't know exaclty how? just add a , after each one possible?
 
Back
Top Bottom