www.webdeveloper.com
Results 1 to 3 of 3

Thread: Problem Listing Categories....

  1. #1
    Join Date
    Jan 2007
    Posts
    215

    Problem Listing Categories....

    I have a major problem that I cannot seem to get solved.

    I have two databases, one called "Ranking" which is used to store my Categories for my different types of ranks. The other is called "Ranking_list" which is used to store my File Name, Title and Rankid (Primary Key of the Ranking table).

    The two databases are meant to be used to display all of my categories for my ranks.

    E.g. Adults, Juniors, Women, Men. - These are examples of my Ranks, and will be stored in table Ranking.

    ranking.php will be used to display these categories in order, and allow them to be anchor links which when clicked will take you to list.php and list all the Files that correspond to the rank.

    E.g. Adults Final, Adults 100 Meters, Adults 200 Meters - These are examples of clickable links which when clicked would prompt the user to download the relevant file.

    I have created several scripts.
    One to create new categories and save them into the table Ranking.

    One to create new files and then select the category, and then the file is uploaded to the file structure and the name written to the Ranking_list table. Keep in mind that the categories are pulled from the Ranking table.

    One to view the categories as clickable links (ranking.php)

    One to view the files related to the categories (list.php)

    I am fairly new to PHP and I am getting through a little, however, I cannot get the list.php to function as it should. Rather than output the list of files, it outputs "SELECT * FROM Ranking_list WHERE Rankid = 1".

    Here is my code:
    Table: Ranking
    Code:
    CREATE TABLE `Ranking` (
      `Rankid` tinyint(2) NOT NULL auto_increment,
      `Title` varchar(100) NOT NULL,
      PRIMARY KEY  (`Rankid`)
    ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

    Table: Ranking_list:
    Code:
    CREATE TABLE `Ranking_list` (
      `id` tinyint(2) NOT NULL auto_increment,
      `Title` varchar(100) NOT NULL,
      `File` varchar(100) NOT NULL,
      `Rankid` tinyint(3) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    Script: ranking.php
    PHP Code:
                        <?
                        
    include("db.php");
                        
    $sqlfeat="Select * from Ranking";
                        
                        
    $resfeat=mysql_query($sqlfeat,$db);
                        
                        
                        while (
    $onefeat=mysql_fetch_object($resfeat))
                        {
                        
                            
                            echo 
    "<li><a href='list.php?cat="$onefeat->Rankid."'>"$onefeat->Title."</a></li>";
                        }
                        
                        
    ?>
    File: list.php
    PHP Code:
    <?php
                
    include("db.php");                                
                
    $id=$_REQUEST['cat'];
                
    $start=$_REQUEST['start'];

                if (isset(
    $_GET['cat']) and is_numeric($_GET['cat'])){
                
    $sqlfea "SELECT * FROM Ranking_list WHERE Rankid = " $_GET['cat'];
                } else {
                    
    $sqlfea="Select * from Ranking_list";
                    
                    
    $linkfea=mysql_query($sqlfea,$db);
                    
                    
                    while (
    $onefea=mysql_fetch_object($linkfea))
                    {
                        echo 
    "<li><a href='/uploads/"$onefea->File."' target='_blank'>";
                        echo 
    $onefea->Title."</a></li>";
                    }
                }  
                echo 
    $sqlfea
    ?>

    As you see from the database above, Ranking_list contains the field Rankid which is the primary key in the table Ranking.
    I tried to follow all the right syntax, but just cannot get the bloody thing working.
    ranking.php works fine and list all the categories as it should, however, list.php does not list ANYTHING. I do not even get an error, I get one output, and that is this: SELECT * FROM Ranking_list WHERE Rankid = 1

    Can ANYONE please guide me in the right direction, this is extremely important that I get this working ASAP. Help anyone please.

  2. #2
    Join Date
    Jan 2005
    Posts
    592
    We all have been there. You made a silly mistake look at this code.

    you say if there is a $_GET['cat'] then sqlfea is this sql query.

    if there is no $GET_['cat'] then run through this code.

    and then at the very end you output sqlfea.



    if there is a $_GET['cat'] you create the sqlquery and store it in sqlfea but you dont do anythinig with it. You just simply outputsqlfea at the end.

    you need to use sqlfea and query the database.

    not sure if this is how you want it to work but try this,


    PHP Code:

    <?php
                
    include("db.php");                                
                
    $id=$_REQUEST['cat'];
                
    $start=$_REQUEST['start'];

                if (isset(
    $_GET['cat']) and is_numeric($_GET['cat'])){
                
    $sqlfea "SELECT * FROM Ranking_list WHERE Rankid = " $_GET['cat'];
                } else {
                    
    $sqlfea="Select * from Ranking_list";
                }    
                    
    $linkfea=mysql_query($sqlfea,$db);
                    
                    
                    while (
    $onefea=mysql_fetch_object($linkfea))
                    {
                        echo 
    "<li><a href='/uploads/"$onefea->File."' target='_blank'>";
                        echo 
    $onefea->Title."</a></li>";
                    }
              
    ?>

  3. #3
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    PHP Code:
    <?php
    include("db.php");
    $id=$_REQUEST['cat'];
    $start=$_REQUEST['start'];

    $WHERE "";
    if (isset(
    $_GET['cat']) and is_numeric($_GET['cat'])) {
      
    $WHERE "WHERE `Rankid` = " $_GET['cat'];
    }

    $sqlfea  "SELECT * FROM `Ranking_list` $WHERE";
    $linkfea mysql_query($sqlfea,$db);

    while (
    $onefea mysql_fetch_object($linkfea)) {
      echo 
    "<li><a href='/uploads/"$onefea->File "' target='_blank'>" $onefea->Title "</a></li>";
    }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles