Jump to content


Photo

Is there a better way to echo/print variables ?


  • Please log in to reply
2 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 July 2006 - 04:30 AM

I have writen a script that was intended to be used for my left_navbar. Which would simply update my left_navbar and my simple bread crumbfile. Ok now to the question.

I am wondering if there is an easier way to do the same thing.

This is an example of were the variables will be pased from.
<?php
$filename = "forum.php";
$title = "Forum";
$cata = "General";
$catb = "Apache";
$catc = "Mysql";
$catd = "Php";
$cate = "Css";
$catf = "Html";
$catg = "Flash";
$cath = "Xampp";
$catI = "Wamp";
$linka = "$filename";
$linkb = "$filename";
$linkc = "$filename";
$linkd = "$filename";
$linke = "$filename";
$linkf = "$filename";
$linkg = "$filename";
$linkh = "$filename";
$linkI = "$filename";
$construct = "true";
include("includes/main.php");
?> 

First this is just a test until I get the forum up and running. the $constuct ="true"; Tells my main.php(the main layout page) that the site is currently under construction and echos the $title to tell the user that the site is down.

Is it possible to write an array at the top of this file and then when the forum.php is called another function will print the array into varibles, like above. I would like to have the array dynamicly updated based on content.

Here is a copy of a copy of my left_navbar.php

  <div id="search"> 
    <form action="#"> 
      <label>search</label> 
      <input name="searchfor" type="text" size="a0"> 
      <input name="goButton" type="submit" value="go"> 
    </form> 
  </div> 
  <div id="sectionLinks">
<?php 
if ($title =="The Home Of Owpt") {
   echo " 
   <h3>Links</h3> 
    <ul> 
      <li><a href=\"index.php\" TITLE=\"The Home Of Owpt\">Home</a></li> 
      <li><a href=\"account.php\" TITLE=\"My Account\">My account</a></li> 
      <li><a href=\"contact.php\" TITLE=\"Contact US\">Contact Us</a></li> 
      <li><a href=\"support.php\" TITLE=\"Support\">Support</a></li>
      <li><a href=\"catalog.php\" TITLE=\"Catalog\">Catalog</a></li> 
      <li><a href=\"Forum.php\" TITLE=\"Forum\">Forum</a></li>
      <li><a href=\"tutorials.php\" TITLE=\"Tutorials\">Tutorials</a></li>
    </ul> 
  </div>"; 
} elseif ($title=="My Account") {
   echo "
    <h3>Links</h3> 
    <ul> 
      <li><a href=\"index.php\" TITLE=\"The Home Of Owpt\">Home</a></li> 
      <li><a href=\"account.php\" TITLE=\"My Account\">My account</a></li> 
    </ul>
  </div>    
  <div class=\"relatedLinks\">
    <ul> 
      <li><a href=\"$linka\" TITLE=\"$cata\">$cata</a></li> 
      <li><a href=\"$linkb\" TITLE=\"$catb\">$catb</a></li> 
      <li><a href=\"$linkc\" TITLE=\"$catc\">$catc</a></li> 
      <li><a href=\"$linkd\" TITLE=\"$catd\">$catd</a></li> 
      <li><a href=\"$linke\" TITLE=\"$cate\">$cate</a></li> 
    </ul> 
  </div>
  <div class=\"afterLinksLinks\">
    <ul>
      <li><a href=\"contact.php\" TITLE=\"Contact US\">Contact Us</a></li> 
      <li><a href=\"support.php\" TITLE=\"Support\">Support</a></li>
      <li><a href=\"catalog.php\" TITLE=\"Catalog\">Catalog</a></li> 
      <li><a href=\"Forum.php\" TITLE=\"Forum\">Forum</a></li>
      <li><a href=\"tutorials.php\" TITLE=\"Tutorials\">Tutorials</a></li>
    </ul> 
  </div>";
} elseif ($title=="Contact Us") {
   echo "   
   <h3>Links</h3> 
    <ul> 
      <li><a href=\"index.php\" TITLE=\"The Home Of Owpt\">Home</a></li> 
      <li><a href=\"account.php\" TITLE=\"My Account\">My account</a></li> 
      <li><a href=\"contact.php\" TITLE=\"Contact US\">Contact Us</a></li> 
      <li><a href=\"support.php\" TITLE=\"Support\">Support</a></li>
      <li><a href=\"catalog.php\" TITLE=\"Catalog\">Catalog</a></li> 
      <li><a href=\"Forum.php\" TITLE=\"Forum\">Forum</a></li>
      <li><a href=\"tutorials.php\" TITLE=\"Tutorials\">Tutorials</a></li>
    </ul> 
  </div>"; 
} elseif ($title=="Support") {
   echo "  
    <h3>Links</h3> 
     <ul> 
      <li><a href=\"index.php\" TITLE=\"The Home Of Owpt\">Home</a></li> 
      <li><a href=\"account.php\" TITLE=\"My Account\">My account</a></li> 
      <li><a href=\"contact.php\" TITLE=\"Contact US\">Contact Us</a></li> 
      <li><a href=\"support.php\" TITLE=\"Support\">Support</a></li>
     </ul>
  </div>    
  <div class=\"relatedLinks\">
    <ul> 
      <li><a href=\"$linka\" TITLE=\"$cata\">$cata</a></li> 
      <li><a href=\"$linkb\" TITLE=\"$catb\">$catb</a></li> 
      <li><a href=\"$linkc\" TITLE=\"$catc\">$catc</a></li> 
      <li><a href=\"$linkd\" TITLE=\"$catd\">$catd</a></li>
      <li><a href=\"$linke\" TITLE=\"$cate\">$cate</a></li>
    </ul> 
  </div>
  <div class=\"afterLinks\">
     <ul>
      <li><a href=\"catalog.php\" TITLE=\"Catalog\">Catalog</a></li>
      <li><a href=\"Forum.php\" TITLE=\"Forum\">Forum</a></li>
      <li><a href=\"tutorials.php\" TITLE=\"Tutorials\">Tutorials</a></li>
     </ul> 
  </div>";
} elseif ($title=="Catalog") {
   echo "
    <h3>Links</h3>
     <ul>      
      <li><a href=\"index.php\" TITLE=\"The Home Of Owpt\">Home</a></li> 
      <li><a href=\"account.php\" TITLE=\"My Account\">My account</a></li> 
      <li><a href=\"contact.php\" TITLE=\"Contact US\">Contact Us</a></li> 
      <li><a href=\"support.php\" TITLE=\"Support\">Support</a></li>
      <li><a href=\"catalog.php\" TITLE=\"Catalog\">Catalog</a></li>
     </ul>
  </div>      
  <div class=\"relatedLinks\">
    <ul> 
      <li><a href=\"$linka\" TITLE=\"$cata\">$cata</a></li> 
      <li><a href=\"$linkb\" TITLE=\"$catb\">$catb</a></li> 
      <li><a href=\"$linkc\" TITLE=\"$catc\">$catc</a></li> 
      <li><a href=\"$linkd\" TITLE=\"$catd\">$catd</a></li> 
    </ul> 
  </div>
  <div class=\"afterLinks\">
    <ul>        
      <li><a href=\"Forum.php\" TITLE=\"Forum\">Forum</a></li>
      <li><a href=\"tutorials.php\" TITLE=\"Tutorials\">Tutorials</a></li>
    </ul> 
  </div>";
} elseif ($title=="Forum") {
   echo "
    <h3>Links</h3> 
    <ul> 
      <li><a href=\"index.php\" TITLE=\"The Home Of Owpt\">Home</a></li> 
      <li><a href=\"account.php\" TITLE=\"My Account\">My account</a></li> 
      <li><a href=\"contact.php\" TITLE=\"Contact US\">Contact Us</a></li> 
      <li><a href=\"support.php\" TITLE=\"Support\">Support</a></li>
      <li><a href=\"catalog.php\" TITLE=\"Catalog\">Catalog</a></li> 
      <li><a href=\"Forum.php\" TITLE=\"Forum\">Forum</a></li>
    </ul>
  </div>   
  <div class=\"relatedLinks\">
    <ul>
      <li><a href=\"$linka\" TITLE=\"$cata\">$cata</a></li> 
      <li><a href=\"$linkb\" TITLE=\"$catb\">$catb</a></li> 
      <li><a href=\"$linkc\" TITLE=\"$catc\">$catc</a></li> 
      <li><a href=\"$linkd\" TITLE=\"$catd\">$catd</a></li> 
      <li><a href=\"$linke\" TITLE=\"$cate\">$cate</a></li> 
      <li><a href=\"$linkf\" TITLE=\"$catf\">$catf</a></li>
      <li><a href=\"$linkg\" TITLE=\"$catg\">$catg</a></li>
      <li><a href=\"$linkh\" TITLE=\"$cath\">$cath</a></li>
      <li><a href=\"$linkI\" TITLE=\"$catI\">$catI</a></li>
    </ul> 
  </div>
  <div class=\"afterLinks\">
    <ul> 
      <li><a href=\"tutorials.php\" TITLE=\"Tutorials\">Tutorials</a></li>
    </ul> 
  </div>";
} else {
   echo "  
    <h3>Links</h3> 
    <ul> 
      <li><a href=\"index.php\" TITLE=\"The Home Of Owpt\">Home</a></li> 
      <li><a href=\"account.php\" TITLE=\"My Account\">My account</a></li> 
      <li><a href=\"contact.php\" TITLE=\"Contact US\">Contact Us</a></li> 
      <li><a href=\"support.php\" TITLE=\"Support\">Support</a></li>
      <li><a href=\"catalog.php\" TITLE=\"Catalog\">Catalog</a></li> 
      <li><a href=\"Forum.php\" TITLE=\"Forum\">Forum</a></li>
      <li><a href=\"tutorials.php\" TITLE=\"Tutorials\">Tutorials</a></li>
    </ul> 
  </div>
  <div class=\"relatedLinks\">
    <ul> 
      <li><a href=\"$linka\" TITLE=\"$cata\">$cata</a></li> 
      <li><a href=\"$linkb\" TITLE=\"$catb\">$catb</a></li> 
      <li><a href=\"$linkc\" TITLE=\"$catc\">$catc</a></li> 
      <li><a href=\"$linkd\" TITLE=\"$catd\">$catd</a></li> 
      <li><a href=\"$linke\" TITLE=\"$cate\">$cate</a></li> 
      <li><a href=\"$linkf\" TITLE=\"$catf\">$catf</a></li>
      <li><a href=\"$linkg\" TITLE=\"$catg\">$catg</a></li>
      <li><a href=\"$linkh\" TITLE=\"$cath\">$cath</a></li>
    </ul> 
  </div>";
}
?>


As you can see this is also very repeative. It actualy would have been faster to manuly code it with the actual links. Well maybe not. Anyways, this can be broken down into three dynamic areas. The sectionLinks relatedLinks and the afterLinks. When the person clicks on, say forum , the rest of the links that are below move down and the the relatedLinks are put in its place.

So basicly I am wanting to dynamicly store information in the top of a page or maybe some other page..i.e..links.php and inlcude it in my master php file. Here is a link to the site so that you may see it in action http://www.owpt.biz/index.php 

Also I am wondering how to use the session.hash.function()? Or some other form of a more secure session?


Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 02 July 2006 - 05:04 AM

you could do something like...

$links = array("link0", "link1", "link2");
$cats = array("cat0", "cat1", "cat2");

for ($i=0; $i<=count($links); $i++) {
     echo '<a href="'.$links[$i].'">'.$cats[$i].'</a>';
}


you can load the link info manually as in the above example or load it from a text file or database for easy updating

:: gucci.com ::
:: blockbuster.com ::

--------------------

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 July 2006 - 05:45 AM

Thanks I will do some reasearch...i.e.. The manul. On this subject

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users