Help Me Debug this.

Discussion in 'PHP' started by advancedfuture, Mar 13, 2007.

  1. #1
    So I am trying to make nav links for my website... I.E a Previous and Next hyperlink to navigate to the next page. Problem is my code isnt working right.

    This is the PHP code from my index.php page..
    
    <?php
    $page = $_GET['page'];
    urlencode($page);
    if($page > ""){
    	include($page);
    	$base_url = 'http://' .$_SERVER['HTTP_HOST'];
    	$full_path = $_GET['page'];
    	$base = dirname($full_path);
    	$page_file = basename($full_path);
    	$page_num = substr($page_file
    	, strrpos($page_file, "_") + 1
    	, strpos($page_file, ".php") - strrpos($page_file, "_") - 1
    	);
    	$partial_path = substr($page_file, 0, strrpos($page_file, "_"));
    
    	print "<p>base_url=[$base_url]</p>\n";
    	print "<p>full_path=[$full_path]</p>\n";
    	print "<p>base=[$base]</p>\n";
    	print "<p>page_file=[$page_file]</p>\n";
    	print "<p>page_num=[$page_num]</p>\n";
    	print "<p>partial_path=[$partial_path]</p>\n";
    	
    	$prev_page_file = $partial_path . "_" . (string)($page_num-1) . ".php";
    	$next_page_file = $partial_path . "_" . (string)($page_num+1) . ".php";
    	
    	print "<p>prev_page_file=[$prev_page_file]</p>\n";
    	print "<p>next_page_file=[$next_page_file]</p>\n";
    	
    	$prev_full = "/" . $base . "/" . $prev_page_file;
    	$next_full = "/" . $base . "/" . $next_page_file;
    	print "<p>$prev_full</p>\n";
    	print "<p>$next_full</p>\n";
    
    	if (file_exists($prev_full) ==TRUE )
    		{
    		print "<a href=\"$base/$prev_page_file\">previous</a>";
    		if (file_exists($next_full) == TRUE)
    			{
    			print " | ";
    			}
    		}
    	if (file_exists($next_full) == TRUE)
    		{
    		print "<a href=\"$base/$next_page_file\">next</a>";
    		}
    	else {
    		print "does not exist";
    		}
    	}
    	Else{
    	include('main_1.php');
    } 
    ?>
    
    Code (markup):

    Basically what happens is when the user goes to the main page it pulls the page main_1.php... now since its dynamic whenever someone goes to another page it loads that page.... The output I get from my debuggin shows this....


    so all the variables are getting the right information... but the file_exists() function is not finding the file... thus printing the debug info "does not exist"... I can tell you the next file does exist! What is wrong in my code?
     
    advancedfuture, Mar 13, 2007 IP
  2. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    one thing i can suggest is avoid using capitalized "TRUE" ... instead use "true"

    in PHP TRUE != true both are having diffrent meaning ...

    I hope this hint will help you
     
    rays, Mar 13, 2007 IP
  3. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #3
    One more thing


    if (file_exists($prev_full) ==TRUE )

    rather than this just use

    if (file_exists($prev_full))

    because file_exists returns true if file is present else false... so no need to do comparison in if
     
    rays, Mar 13, 2007 IP