0

im new to php

i have a problem..

i wanna design a website that will have index.php as the Home page.
The index.php will include


header.php(the universal header)
menu.php(unuversal menu)
topics.php(topics of my websites like global warming,child labour etc..)
content.php(a welcome note for Home page.)

___________________________________________________


header.php


___________________________________________________
| menu.php
|
|
|
|
|
|
|
topics.php | content.php
|
|
|
|
|
|
|
_____________________________________________________


I wanna now focous on topic.php file.This page will hold the list of my website topics.
i wanna design my website in such a way that when any user click on any topic (suppose global warming )the
application will automatically include global_warming.php(which i have created earlier) in the index.php
page and show the content of global_warming.php file in place of content.php in a iframe.
and will do the same for other topics.

Thanks...

3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by hielo
1

I would suggest staying away from Iframes as many browsers don't have good support for them. Instead I would recommend using html <div> tags to display each 'section'. Then each topic has a hyperlink that references content.php with an added topic variable.

Eg:

Topics:
<a href="content.php?topic=12">Global Warming</a>
<a href="content.php?topic=13">Child Labour</a>

Each link has a topic ID (?topic=12) - which links to each article in your database.

Then on content.php, get the value of the URL topic variable and dynamically fetch the corresponding topic content.

<?php
$topic = $_GET['topic'];
$get_topics = mysql_query("SELECT article FROM topics_table WHERE topic_id = '$topic'") or die(mysql_error());
$result_topic = mysql_fetch_assoc($get_topics);
?>

<div id = "article">
   <?php echo $result_topic['article']; ?>
</div>

I assume you're using a database for your topics and articles?! This way, your site will be much more scalable :)

Edited by nonshatter: n/a

Votes + Comments
0

thanks a lot...but i donno this question is goin to be too silly or not but i don't how put pages(.php,.html etc) in a mysql database.

i have another question that if my included page is too long.would i get a scroll bar(like iframe).???

0

That's no problem! First of all, you don't put pages into a database, you put the pages content into various fields (columns) of the database table. So if you were to create a database for your site, you would have a table containing the topics:

| topic_id | topic_title | topic_hyperlink |

Maybe another table containing articles:

| article_id | topic_id | article_title | article_content | article_author | article_comments |

etc..

To answer your other question, yes you can set <div> tags to have a scroll bar using the CSS property 'overflow: auto;' - This will create a scrollbar - horizontal, vertical or both only if the content in the block requires it. For practical web development, this is probably the most useful approach to creating a scrollbar.

To be clear:

<div id="article" style="overflow:auto;"> content </div>

Edited by nonshatter: n/a

0

Yes, you could create each topic page manually, but that would be a nightmare to maintain if your site keeps growing.

If this is a personal site (like a blog), then you may want to look at a blogging platform like WordPress

0

if you want to use just files, from what you posted earlier, try using this as your topics.php (just add more topics to the $topics array)

<?php
//FYI: the 234 and the 745 are meant to be "random". In other words, you can assign whatever numbers you want.
$topics=array(	'234'=>array('file'=>'globalwarming.php','text'=>'Global Warming')
				,'745'=>array('file'=>'child-labour.php','text'=>'Child Labour')
			);
$menu='';
foreach($topics as $key=>$property){
	$menu .=sprintf('|<a href="?id=%s">%s</a>',$key, htmlentities($property['text'],ENT_QUOTES) );
}
echo '<div>'.substr($menu,1).'</div>';
if( isset( $_GET['id']) && isset( $topics[ intval($_GET['id']) ] ) )
{
	require_once( $topics[ intval($_GET['id']) ]['file'] );
}
?>

Edited by hielo: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.