Results 1 to 7 of 7

Thread: Function within a function? I don't think I have this right

  1. #1
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Function within a function? I don't think I have this right

    PHP Code:
    <?php
    echo "<h3>Sociology</h3>";
    echo 
    "<ul>";
    $theuri $_SERVER['REQUEST_URI']; // Check URL
      
    if (!$myxml=simplexml_load_file('research_sociologyindex.xml')){
        echo 
    'Error reading the XML file';
    }
    foreach(
    $myxml as $article){
      if ( (
    $theuri =="' . $article->link . '") ) { // If the URL is this page
          
    $itemis '<li><b>' $article->title '</b></li>'// Disable link if visitor is on this page
      
    } else {
          
    $itemis '<li><a href=' $article->link '>' $article->title '</a></li>'// Generate functional link
      
    }
    }
    echo 
    "</ul>";
    ?>
    All I want to do is have a list of links that is automatically generated by an external XML file; And when a person is on the page, to disable the link to that page (because he/she is already on it).

    The above script dosent return any errors, but it just displays the <h3> title, so I know I'am close; to the annoyance of my girlfriend I was tinkering around with it on a napkin at dinner a bit and of course ended up with a completely different script ... and the 'silent treatment'

    Best Regards
    ~Spine
    Last edited by Spinethetic; 06-19-2008 at 01:19 PM. Reason: Added in some PHP comments

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, try this:
    PHP Code:
    <?php
    echo "<h3>Sociology</h3>";
    echo 
    "<ul>";
    $theuri $_SERVER['REQUEST_URI'];
    if (
    $myxml!=simplexml_load_file('research_sociologyindex.xml')){

    die(
    'Error reading the XML file');

    }

    foreach(
    $myxml as $article){
    if ( (
    $theuri == $article->link) ) {
    $itemis ="<li><b>  $article->title  </b></li>";
    } else {
    $itemis "<li><a href=$article->link>$article->title</a></li>";
    }
    }
    echo 
    "</ul>";
    ?>
    Also, can I please see the whole code, that may help...
    Jeremy | jfein.net

  3. #3
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by Nile View Post
    Ok, try this:
    PHP Code:
    <?php
    echo "<h3>Sociology</h3>";
    echo 
    "<ul>";
    $theuri $_SERVER['REQUEST_URI'];
    if (
    $myxml!=simplexml_load_file('research_sociologyindex.xml')){

    die(
    'Error reading the XML file');

    }

    foreach(
    $myxml as $article){
    if ( (
    $theuri == $article->link) ) {
    $itemis ="<li><b>  $article->title  </b></li>";
    } else {
    $itemis "<li><a href=$article->link>$article->title</a></li>";
    }
    }
    echo 
    "</ul>";
    ?>
    Also, can I please see the whole code, that may help...
    That outputs the same thing as originally. That basically is the whole script. I can include these scripts I use that I deduced I would be able to set this up: research_sociologyindex.xml
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
       <sociology>
    
          <article>
             <title>Thoughts on the Evolution of Social Inequality: A Paradigmatic Analysis</title>
             <description>American anthropology is in a state of theoretical crisis. Unlike most mature scientific disciplines anthropolologists seem unable even to agree on the structure of our discipline or the most important research questions to ask, let alone the best way to develop theory and increase our understanding of the human world. How is productive research possible in such an intellectual climate? In the early 1960’s, philosopher Thomas Kuhn argued that scientific disciplines periodically pass through "revolutionary" changes in theory (1970). According to Kuhn, these changes occur when a dominant paradigm or theoretical framework fails to account for empirical observations and when a better paradigm is developed...</description>
             <link>research_sociology_toteosiapa.htm</link>
          </article>
    
          <article>
             <title>Why we hate complexity</title>
             <description>Natural and social systems are complex -- that is, not entirely knowable, unpredictable, resistant to cause-and-effect analysis, in a word, mysterious. For our first three million years on Earth we humans, like every other species on the planet, accepted that mystery. We adapted rather than trying to change our environment. We evolved by learning to accommodate ourselves to our environment. Those unable to accommodate perished....</description>
             <link>research_sociology_wwhc.htm</link>
          </article>
    
       </sociology>
    I have catagory index pages setup using similiar XML files, EXAMPLE using code:
    PHP Code:
    <?php
    if (!$myxml=simplexml_load_file('research_sociologyindex.xml')){
            echo 
    'Error reading the XML file';
            }
            foreach(
    $myxml as $article){
                    echo 
    '<center><img src=','images/upperlotushalf.jpg','></center>';
                    echo 
    '<blockquote><h3> ' $article->title '</h3>';      
                    echo 
    '' $article->description '<br />';  
                    echo 
    '<a href=','' $article->link '',' class=','button','><span>Continue reading...</span></a></blockquote><br />';
            }
    ?>
    rightside_sociologyresearch.php
    PHP Code:
    <?php
        
    echo "<h3 class='leftrightheader'>Sociology</h3>";
    $theuri $_SERVER['REQUEST_URI'];
        echo 
    "<ul>";
      if ( (
    $theuri =="/research_sociology_toteosiapa.htm") ) {
    $itemis "<li><b>Thoughts on the Evolution of Social Inequality: A Paradigmatic Analysis</b></a></li>";
      } else {
    $itemis "<li><a href='research_sociology_toteosiapa.htm'>Thoughts on the Evolution of Social Inequality: A Paradigmatic Analysis</a></li>"
    }
    echo 
    $itemis;

      if ( (
    $theuri =="/research_sociology_wwhc.htm") ) {
    $itemis "<li><b>Why we hate complexity</b></a></li>";
      } else {
    $itemis "<li><a href='research_sociology_wwhc.htm'>Why we hate complexity</a></li>"
    }
    echo 
    $itemis;
        echo 
    "</ul>";
    ?>
    I figured I would be able to set something up where I wouldent have to constantly update any of the "rightside_whateverresearch.php" files everytime I load a new article.

    Best Regards
    ~Spine

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well, I've never worked with xml files in php, sorry. I just guessed. :-/
    Jeremy | jfein.net

  5. #5
    Join Date
    Jun 2008
    Location
    Denham Springs, LA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:

    foreach($myxml as $article){
       if ( (
    $theuri == $article->link) ) {
          
    $itemis ="<li><b>  $article->title  </b></li>";
       } else {
        
    $itemis "<li><a href=$article->link>$article->title</a></li>";
        }

       echo 
    $itemis;

    }

    echo 
    "</ul>";
    ?> 
    Maybe I'm missing something here, but why didn't you just echo out the $itemis variable, If you don't print anything it will never display.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    If you look in Spinethetic's previous code, it was echo'd:
    PHP Code:
    <?php
        
    echo "<h3 class='leftrightheader'>Sociology</h3>";
    $theuri $_SERVER['REQUEST_URI'];
        echo 
    "<ul>";
      if ( (
    $theuri =="/research_sociology_toteosiapa.htm") ) {
    $itemis "<li><b>Thoughts on the Evolution of Social Inequality: A Paradigmatic Analysis</b></a></li>";
      } else {
    $itemis "<li><a href='research_sociology_toteosiapa.htm'>Thoughts on the Evolution of Social Inequality: A Paradigmatic Analysis</a></li>"
    }
    echo 
    $itemis;

      if ( (
    $theuri =="/research_sociology_wwhc.htm") ) {
    $itemis "<li><b>Why we hate complexity</b></a></li>";
      } else {
    $itemis "<li><a href='research_sociology_wwhc.htm'>Why we hate complexity</a></li>"
    }
    echo 
    $itemis;
        echo 
    "</ul>";
    ?>
    Of course that code at the end could be shorted.
    Jeremy | jfein.net

  7. #7
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by josephhamilton1 View Post
    PHP Code:

    foreach($myxml as $article){
       if ( (
    $theuri == $article->link) ) {
          
    $itemis ="<li><b>  $article->title  </b></li>";
       } else {
        
    $itemis "<li><a href=$article->link>$article->title</a></li>";
        }

       echo 
    $itemis;

    }

    echo 
    "</ul>";
    ?> 
    Maybe I'm missing something here, but why didn't you just echo out the $itemis variable, If you don't print anything it will never display.
    Because for instance, when I goto article "why we hate complexity" I want the link in the right sidebar to 'gray-out', because the visitor is already on this page. The way I had rightside_sociologyresearch.php set up does in fact work this way. What it is doing now, is indeed loading data from the XML file, but it is not graying out the page links that I am currently on.

    Best Regards
    ~Spine

    edit: here is one of the two pages I include the script, functioning as I just described: LINK
    Last edited by Spinethetic; 06-20-2008 at 03:15 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •