PDA

View Full Version : Creating a new page with PHP..


Mark_W
06-07-2007, 11:47 PM
Hi guys and girls,

Right as you know I've only really started learning PHP over the past 3 or 4 weeks, although I like to think I've come along way during that time, even with my limited spare time.

Using the VTs I have managed to create a system whereby I can change the latest news on the main page of a website (even limiting it to the latest 5 submitted).

However, this Isn't the full system I want. I have put a link on each latest content to view the full article. I don't want to have to go through dreamweaver every time I want to add new content.

So how would I go about creating a new page complete with a consistent layout as the rest of the site?

I hope that is easy to understand.

Thanks for your help,

Mark

davidj
06-08-2007, 06:38 AM
so you want to add content then display on a new page?

Mark_W
06-08-2007, 10:43 AM
Yes that would be the simple way of putting it.

davidj
06-08-2007, 10:45 AM
just have the 1 page and display the content from your db

are you passing content from 1 page to another?

Mark_W
06-08-2007, 11:33 AM
Erm, I don't know really.

If you take a quick look at this website www.holmesdale.net (http://www.holmesdale.net) you will notice that they have 4 sets of latest news, at the end of each news they have a 'more on this story' link which takes them to a full page with that article. What I invision is that they have a form similar to the one I will show you in a second.

I havent really thought this through, so I will give an explanation of the administration page.

Below is a form which I would use to add new content.

<form id="form1" name="form1" method="post" action="">
<label>News Title
<input type="text" name="textfield" id="textfield" />
</label>

<label>News Brief
<textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
</label>

<!-- The content in the above text area is what the user would see on the main page, this would just be a small brief of what the article is about, for example. -->

<label>News Content
<textarea name="textarea2" id="textarea2" cols="45" rows="5"></textarea>
</label>

<!-- The content in the above text area is the full article, this would be displayed on a new page and would be linked from the main page -->

<label>News URL
<input type="text" name="textfield2" id="textfield2" />
</label>
<br />
</p>
</form>Once the form has been submitted, would I would like to happen is the 'News Brief' would show up on the main page (which I can already do) and a new page would be created with the 'News Content' shown on the page.

I believe all of this is possible, I may be mistaken though.

davidj
06-08-2007, 11:37 AM
so the news brief would be a few words of the actual news story. When you click more you would be taken to the full article.

Mark_W
06-08-2007, 11:38 AM
Yeah that's exactly it.

davidj
06-08-2007, 11:51 AM
gotcha

design your front page where you want the news snippet to be displayed

wher you have the $var which is displaying your news just use a sub_str() function

in this example 0 = the begining of the text and 40 = how much text to show..
<?php echo sub_str($row['news'], 0, 40); ?>

each news item in the db should have an ID number. You need to assign this number to a link which gets passed to the detail page

<a href="detail_page.php?id=<?php echo $row['id']; ?>" >More</a>

in the detail page you would have this...

$id = $_GET['id'];

///
then your SQL which displays the news looks like this

select * from table where news_id = $id

does this make sense..

Mark_W
06-08-2007, 12:07 PM
'Does it make sense?'

I admit I had a bit of trouble, but then realised it was because I hadn't changed the names to my relevant database fields.

That makes sense. What doesn't make sense however is how it is so simple to do!

Thank you once again davidj for the help you have given me.

davidj
06-08-2007, 03:46 PM
ok

basicaly just create 2 pages

page 1 = news snippet

page 2 = detail news (all of it)

get these 2 pages displaying the same info and we will tweak this together

Mark_W
06-08-2007, 03:54 PM
Sorry, I'm confused now, I thought we had just sorted it out? It works for me.

davidj
06-08-2007, 04:10 PM
ok

as long as you understand thats fine

just come back if you run into difficulty

Mark_W
06-08-2007, 04:44 PM
Thank you once again for your help.

Can I just ask though, what was it you were going to show me next?

davidj
06-08-2007, 04:48 PM
was just going to show you in stages

"build this first and come back... type thing"

if your ok with it the give it a try but if you run into difficulty just give me a shout

Mark_W
07-21-2007, 02:54 PM
I apologise for bringing this topic to the top again, however I was using the below information for something I'm doing at the moment.

I had trouble following it, but looked at the php manual and noticed that David had made a small mistake, it should be substr not sub_str. That worked for me, so just in case anyone follows the thread in the future, you may find that 'sub_str($row..' doesn't work.

have the $var which is displaying your news just use a sub_str() function

in this example 0 = the begining of the text and 40 = how much text to show..
<?php echo sub_str($row['news'], 0, 40); ?>

davidj
07-21-2007, 02:56 PM
yes thats right

i made a boob

my super powers failed me