Jump to content

php include question


Recommended Posts

ok, on this page: http://codejunkies.geektyme.org/

 

I want the "center" field (where it says "this section of...blahblahblah") to be an include from php, and i want to make the links that i'll be putting on the left to load a different page into the center when you click on them. so who's got some quick code tips for me?

Link to comment
Share on other sites


the easy way:

links to the left are in the format

<a href="mainpage.php?page=page1">page1</a>

<a href="mainpage.php?page=page2">page2</a>

 

then the mainpage.php would have something like this

<? include($_GET


); ?>

 

the downside is that each link would reload the page ... but that pretty normal.

 

an example of this

http://loudas.com/coding.php

I have a directory called shared_code

paul@asmith shared_code $ ls
XF86Config  move.tutorial                raid.php
index.php   postfix_virtual_hosting.php  xhtml1.1.template
paul@asmith shared_code $

 

in coding.php .. I have this

<?
if($_GET[c]) {
       include("shared_code/$_GET[c]");
       } else {
       include("shared_code/index.php");
       }
?>

 

this is my menu for the coding page

paul@asmith shared_code $ cat index.php
       <span class="coding-text">My shared code</span>
       <br />
<p class="general-text">
     <a class="clink" onclick="codingLink('xhtml1.1.template');return false;" href="coding.php?c=xhtml1.1.template" onfocus="blur()" title="XHTML 1.1 Template">XHTML 1.1 Template</a><br />
     <a class="clink" onclick="codingLink('raid.php');return false;" href="coding.php?c=raid.php" onfocus="blur()" title="Software RAID">Software RAID</a><br />
     <a class="clink" onclick="codingLink('postfix_virtual_hosting.php');return false;" href="coding.php?c=postfix_virtual_hosting.php" onfocus="blur()" title="Postfix Virtual Hosting">Postfix Virtual Hosting</a><br />
     <a class="clink" onclick="codingLink('move.tutorial');return false;" href="coding.php?c=move.tutorial" onfocus="blur()" title="Renaming file extensions">Renaming file extensions</a><br />
     <a class="clink" onclick="codingLink('XF86Config');return false;" href="coding.php?c=XF86Config" onfocus="blur()" title="Configuring XFree86">Configuring XFree86</a><br />
</p>
paul@asmith shared_code $

 

and here is example of one of my code snippets:

paul@asmith shared_code $ cat xhtml1.1.template
       <span class="coding-text">XHTML1.1 template</span>
<br />
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";<br />
<!DOCTYPE<br />
   html PUBLIC "-//W3C//DTD XHTML 1.1//EN"<br />
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><br />
<br />
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" ><br />
<head><br />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><br />
        <meta name="Description" content="Your Description" /><br />
        <link rel="shortcut icon" href="http://www.yourdomain.com/favicon.ico" /> <!-- this makes your site look nice --><br />
        <link rel="stylesheet" type="text/css" href="style.css" /> <!-- all display of the site should be done with CSS --><br />
        <title>Your Title</title><br />
<br />
        <script type="text/javascript" src="Javascript.js"></script> <!-- an example Javascript included --><br />
        <script type="text/javascript"><br />
        JavascriptFunction(); // an example of how to execute a javascript function<br />
        </script><br />
</head><br />
<br />
<body><br />
        <div class="css_class"> <!-- doo all the display with CSS, and uses class= --><br />
                Some text<br />
        </div><br />
</body><br />
</html><br />

paul@asmith shared_code $

 

ok thats the easy (and PHP) way :)

 

another possible option would be to use javascript preload the text that you want on each page

then you could create a menu entry like this

<javascript>
var $PAGE1 = "use javascript to load the text":
</javascript>
<a href="#" onclick="Javascript:this.pagelocation.text=$page">Page1</a>

obviously I haven't done this .. otherwise I would have an example ;)

Link to comment
Share on other sites

You could use yucky frames.

You can uses javascript variables to populate a container like paul suggested, i use something similar for my works db app(mainly dynamic form selects and other elements).

Disadvantage is you need to load all the content at once, may seem to take a long time for your page to load, and you will be wasting bandwidth if the user only wants to look at a few things.

Link to comment
Share on other sites

Here is an example of using hidden divs for display.

Basic idea: in your table cell you have a bunch of divs which contain display contents, the first display page is set to display(display: block) the rest are "display: none"

the selectDiv() function takes a divs name as the argument checks if it is all ready displayed via the divDisplay variable. If not sets the currently displayed div to "display: none" and changes divDisplay to the new divs name, then sets the new divs display as visible.

 

<html>
<head>
 <title>Code Junkies</title>
 <link rel="stylesheet"
href="http://codejunkies.geektyme.org/codejunkies.css" type="text/css">
 <script language="javascript">
 <!--
 var divDisplay="first";
 function selectDiv(divName)
 {
   if(divName != divDisplay)
   {    
   document.getElementById(divDisplay).style.display="none"; 
   divDisplay=divName;
   document.getElementById(divDisplay).style.display="block"; 
   }
 }
 // -->
 </script>
</head>
<body
style="background-image: url(http://codejunkies.geektyme.org/background.jpg);">
<table align="center" border="0" cellspacing="0" height="100%"
width="740">
 <tbody>
   <tr>
     <td class="tables" colspan="2" height="70">
     <center><img src="http://codejunkies.geektyme.org/toplogo.png"></center>
     </td>
   </tr>
   <tr>
     <td class="linkstable" colspan="2" height="40">
     <center> Coming Soon </center>
     </td>
   </tr>
   <tr>
     <td class="lefttable" valign="top" width="80">
     <center> Projects<br>
     <a href="#" onclick="selectDiv('first');">first div</a><br>
     <a href="#" onclick="selectDiv('second');">second div</a><br>
     <a href="#" onclick="selectDiv('third');">third div</a><br>
     </center>
     </td>
     <td class="middletable" valign="top">
     <center> This section of geektyme.org is under construction. </center>
     <div id="first" style="display: block;">
     <p>Here is some stuff in div 1</p>
     </div>
     <div id="second" style="display: none;">
     <p>Here is some stuff in div 2</p>
     </div>
     <div id="third" style="display: none;">
     <p>Here is some stuff in div 3</p>
     </div>
     </td>
   </tr>
   <tr>
     <td class="bottomtable" colspan="2" height="40">
     <center> <font size="0">Copyright 2004 mark of <a
href="http://www.geektyme.org/">geektyme.org</a><br>
     </font></center>
     <font size="0"> </font></td>
   </tr>
 </tbody>
</table>
</body>
</html>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...