PHP not displaying categories anymore

Discussion in 'PHP' started by scoopy82, Jan 22, 2009.

  1. #1
    Hi,

    Somewhere after years of upgrades and updates I have lost my categories.

    The code from the page that still correctly pulls the info from the database and displays their links is:
    <?
    	$category1sql = mysql_query ("SELECT ID, Level, Belongs, Name FROM category WHERE Level = 1 LIMIT 0, 6");
    //Print table start
    while ($Get1Posts = mysql_fetch_array($category1sql))
    {
    	$Cat1ID = $Get1Posts['ID'];
    	$Cat1Level = $Get1Posts['Level'];
    	$Cat1Belongs = $Get1Posts['Belongs'];
    	$Cat1Name = $Get1Posts['Name'];
    	
    	Print "<b><a href='/category/$Cat1ID' title='$Cat1Name'>$Cat1Name<a/></b><br>";
    	
    	//Try next Level
    	$category2sql = mysql_query ("SELECT ID, Level, Belongs, Name FROM category WHERE Level = 2 AND Belongs = $Cat1ID");
    	while ($Get2Posts = mysql_fetch_array($category2sql))
    	{
    		$Cat2ID = $Get2Posts['ID'];
    		$Cat2Level = $Get2Posts['Level'];
    		$Cat2Belongs = $Get2Posts['Belongs'];
    		$Cat2Name = $Get2Posts['Name'];
    		
    		Print "&nbsp;&nbsp;<a href='/category/$Cat2ID' title='$Cat2Name'>$Cat2Name</a><br>";
    		
    		//Try next level
    		$category3sql = mysql_query ("SELECT ID, Level, Belongs, Name FROM category WHERE Level = 3 AND Belongs = $Cat2ID");
    		while ($Get3Posts = mysql_fetch_array($category3sql))
    		{
    			$Cat3ID = $Get3Posts['ID'];
    			$Cat3Level = $Get3Posts['Level'];
    			$Cat3Belongs = $Get3Posts['Belongs'];
    			$Cat3Name = $Get3Posts['Name'];
    			
    			Print "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/category/$Cat3ID' title='$Cat3Name'>$Cat3Name</a><br>";
    		}
    	
    	}					
    	
    }	
    		?>
    Code (markup):
    This would take you to the file, "category" which is one folder above. That code produces nothing but MySQL errors now... although I suspect its something else going wrong here.

    The code from the file, "category":
    <?
    
    $var_array = explode("/",$_SERVER[PHP_SELF]);
    
    $CatID = $var_array[1];
    $page = $var_array[2];
    
    // $ArticleCat = $var_array[1];
    
    ?>
    
    <?
    ///////////////////////////////////////////////////////////////////
    $CategoryCount = 1;
    //Get the first category
    $categorysql = mysql_query ("SELECT ID, Name, Belongs FROM category WHERE ID = $CatID");
    Print mysql_error();
    //Get First Records and put into the array
    $CategoryID[$CategoryCount] = mysql_result($categorysql, 0, "ID");
    $CategoryName[$CategoryCount] = mysql_result($categorysql, 0, "Name");
    $CategoryBelongs[$CategoryCount] = mysql_result($categorysql, 0, "Belongs");
    $CatBelongs = $CategoryBelongs[$CategoryCount];
    //Print "CatID = $CatID, $CategoryID[$CategoryCount]";
    $TheEnd = false;
    
    //Get we have a categories
    If($CatBelongs != 0)
    {
    //Put all the category struture in the array
    While (!$TheEnd)
    {
    	$CategoryCount++;
    	$categorysql = mysql_query ("SELECT ID, Name, Belongs FROM category WHERE ID = $CatBelongs");
    	$CategoryID[$CategoryCount] = mysql_result($categorysql, 0, "ID");
    	$CategoryName[$CategoryCount] = mysql_result($categorysql, 0, "Name");
    	$CategoryBelongs[$CategoryCount] = mysql_result($categorysql, 0, "Belongs");
    	$CatBelongs = $CategoryBelongs[$CategoryCount];
    	If($CatBelongs == 0)
    	{
    		$TheEnd = true;
    	}
    	If($CategoryCount > 10)
    	{
    		$TheEnd = true;
    	}
    	//Print $CategoryName[$CategoryCount] . "&nbsp;>>&nbsp;";
    }
    }
    ////////////////////////////////////////////////////////////////////
     $MainKeyword = "$CategoryName[1]"; Include ("includes/header.php"); ?>
    Code (markup):
    ~or~ the links are possibly getting redirected via .htaccess file to another similar piece of code. I have tried all kinds of things to figure this out and get it working... but not having any luck.

    Any suggestions ?
     
    scoopy82, Jan 22, 2009 IP
  2. prasunsen

    prasunsen Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What is the Mysql error you get?
     
    prasunsen, Jan 22, 2009 IP
  3. t3nt3tion

    t3nt3tion Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It may be your mysql connections failing.
     
    t3nt3tion, Jan 22, 2009 IP
  4. scoopy82

    scoopy82 Active Member

    Messages:
    838
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    70
    #4
    I had gotten the same "MySQL" error before fixing another part of the site... which was fixed by adding a / to subfolder in $var_array = explode("/subfolder",$TheURL); Things like that are not working for the categories.

    If it was a MySQL connection or syntax error... What would be wrong ? It works to display the categories... I just can't get it to display from the links now. The database has these fields under category:
    `category` (`ID`, `Level`, `Belongs`, `Name`)
     
    scoopy82, Jan 22, 2009 IP
  5. prasunsen

    prasunsen Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm sorry but I can't really understand you. Which part exactly doesn't work and what is the exact error you are getting?
     
    prasunsen, Jan 22, 2009 IP
  6. scoopy82

    scoopy82 Active Member

    Messages:
    838
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    70
    #6
    Really appreciate the responses :) I will try to explain this again from the top.

    The site in question has a large database of articles filed within various categories. There is a page that will list all the articles by title and linked like so,
    http://www.mysite.org/article187902
    Code (markup):
    The links work correctly and will display the article on its own page. (we have previously encountered a similar problem which we fixed with a path issue)

    There is another page to list all of the categories by their subject titles. The page displays the subjects and is linked like so,
    http://www.mysite.org/category/531
    Code (markup):
    When you click on these links... we get the following errors:
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 20
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 21
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 22
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 23
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 24
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 25
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 26
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 27
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 28
    
    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /public_html/getarticle/articles_new.php on line 29
    
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /public_html/getarticle/articles_new.php on line 37
    
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /public_html/getarticle/articles_new.php on line 38
    
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /public_html/getarticle/articles_new.php on line 39
    Code (markup):
    Both sets of links are rewritten via the htaccess as such
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /getarticle/articles_new.php [L,QSA]
    Code (markup):
    And the code from "articles_new.php is:
    <?php
    $TheURL = $_SERVER['REQUEST_URI'];
    $var_array = explode("/",$TheURL);
    $GotURL = $var_array[1];
    
    $ArticleID = substr($GotURL, 7);
    settype($ArticleID, "integer");
    
    $articlesql = mysql_query ("SELECT ID, Category, Author, Email, Title, ArticleBody, ArticleBlurb, DateSub, DateAct, URL, Active FROM articles WHERE ID = $ArticleID AND Active = 1");
    
    $CheckFound = mysql_num_rows($articlesql);
    If ($CheckFound == 0)
    {
    	//404 redirect
    	//header("Location: /index.php");
    }
    $ArtID = mysql_result($articlesql, 0, 'ID');
    $ArtCategory = mysql_result($articlesql, 0, 'Category');
    $ArtAuthor = mysql_result($articlesql, 0, 'Author');
    $ArtTitle = mysql_result($articlesql, 0, 'Title');
    $ArtBody = mysql_result($articlesql, 0, 'ArticleBody');
    $ArtBlurb = mysql_result($articlesql, 0, 'ArticleBlurb');
    $ArtDateSub = mysql_result($articlesql, 0, 'DateSub');
    $ArtDateAct = mysql_result($articlesql, 0, 'DateAct');
    $ArtURL = mysql_result($articlesql, 0, 'URL');
    $ArtActive = mysql_result($articlesql, 0, 'Active');
    
    	$CategoryCount = 1;
    //Get the first category
    $categorysql = mysql_query ("SELECT ID, Name, Belongs FROM category WHERE ID = $ArtCategory");
    Print mysql_error();
    
    //Get First Records and put into the array
    $CategoryID[$CategoryCount] = mysql_result($categorysql, 0, 'ID');
    $CategoryName[$CategoryCount] = mysql_result($categorysql, 0, 'Name');
    $CategoryBelongs[$CategoryCount] = mysql_result($categorysql, 0, 'Belongs');
    $CatBelongs = $CategoryBelongs[$CategoryCount];
    //Print "CatID = $CatID, $CategoryID[$CategoryCount]";
    $TheEnd = false;
    
    //Get we have a categories
    If($CatBelongs != 0)
    {
    //Put all the category struture in the array
    While (!$TheEnd)
    {
    	$CategoryCount++;
    	$categorysql = mysql_query ("SELECT ID, Name, Belongs FROM category WHERE ID = $CatBelongs");
    	$CategoryID[$CategoryCount] = mysql_result($categorysql, 0, "ID");
    	$CategoryName[$CategoryCount] = mysql_result($categorysql, 0, "Name");
    	$CategoryBelongs[$CategoryCount] = mysql_result($categorysql, 0, "Belongs");
    	$CatBelongs = $CategoryBelongs[$CategoryCount];
    	If($CatBelongs == 0)
    	{
    		$TheEnd = true;
    	}
    	If($CategoryCount > 10)
    	{
    		$TheEnd = true;
    	}
    	//Print $CategoryName[$CategoryCount] . "&nbsp;>>&nbsp;";
    }
    }
    	
    	$MainKeyword = "$ArtTitle";
    	$MainCategory = $CategoryName[1];
    
    ?>
    Code (markup):
     
    scoopy82, Jan 22, 2009 IP
  7. Gangsta

    Gangsta Active Member

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    try replace $TheURL = $_SERVER['REQUEST_URI'];
    with $TheURL = ereg_replace("^/", "", $_SERVER['REQUEST_URI']);

    and tell me the result
    ir simply pm me url and I will try to help you
     
    Gangsta, Jan 22, 2009 IP
  8. prasunsen

    prasunsen Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Put
    echo "SELECT ID, Name, Belongs FROM category WHERE ID = $ArtCategory";

    on line 21 and see what is it showing. Is it displaying the expected query or is $ArtCategory something unexpected.

    In general, each time when you are getting anything unexpected, print your queries to see where exactly the variables start getting funny.
     
    prasunsen, Jan 23, 2009 IP
  9. Panzer

    Panzer Active Member

    Messages:
    381
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #9
    Adding or die(); After the queries will help you pinpoint where things are going wrong.
     
    Panzer, Jan 23, 2009 IP