Dynamic title code

Discussion in 'PHP' started by 3DCADForums, Sep 11, 2010.

  1. #1
    Hello,

    I am new to PHP and I have been trying to create a dynamic title by seeing examples in web world and I finally got this code to work:

    <head><title>
    <?php 
    require("includes/connectdb.php");
    $nr_tresources=0;
     $count_resources=mysql_query("SELECT * from resources");
     while ($count_my_resources=mysql_fetch_array($count_resources))
     {
     $nr_tresources++;
     }
    
    
    if (isset($_REQUEST['id_cat']))
       {
       $id_cat=$_REQUEST['id_cat'];
       } else {$id_cat=0;}
      if (is_numeric($id_cat)==false)
       {$id_cat=0;}
     $lista_cat=mysql_query("SELECT * from resource_categories where id=$id_cat");
     $rez_cat=mysql_fetch_array($lista_cat);
     if (empty($rez_cat))
      {
      $id_cat=0;
      }
      
     $get_categories=mysql_query("SELECT * from resource_categories order by name ASC");
      while ($show_categories=mysql_fetch_array($get_categories))
    $name=$show_categories['name'];
     
      if ($id_cat!=$show_categories['id'])
    	echo "3ds Max Resources&nbsp; >>&nbsp; $name";
      else
            echo "3dsmax Resources | Free tutorial directory with over $nr_tresources tutorials listed ";
    
    ?></title>
    Code (markup):
    You can visit the following page to see yourself: http://www.3dsmaxresources.com/list_resources.php

    The problem is that when I visit the any category in the resources section in the title it is showing the same category name instead of the concerned category that I visit. The main resources page is being displayed properly as per my wish but not the categories section.

    The sql table code is as shown below:

    Table structure for table `resource_categories`
    --
    
    CREATE TABLE IF NOT EXISTS `resource_categories` (
      `id` bigint(15) NOT 
    
    NULL auto_increment,
      `name` varchar(50) NOT NULL,
      `date` date NOT NULL,
      `time` time NOT NULL,
      PRIMARY KEY  (`id`)
    ) 
    
    ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;
    
    --
    -- Dumping data for table `resource_categories`
    --
    
    INSERT INTO 
    
    `resource_categories` (`id`, `name`, `date`, `time`) VALUES
    (2, 'Animation', '2008-08-23', '20:48:34'),
    (3, 'Materials', 
    
    '2008-08-23', '20:48:44'),
    (4, 'Basics', '2008-08-23', '20:48:52'),
    (5, 'Modeling', '2008-08-23', '20:49:01'),
    (6, 
    
    'Lighting', '2008-08-23', '20:50:11'),
    (7, 'Reactor', '2008-08-23', '20:51:03'),
    (8, 'Text Effects', '2008-08-23', 
    
    '20:51:52'),
    (9, 'Books', '2008-08-23', '20:52:08'),
    (10, 'Freewares', '2008-08-23', '20:53:17'),
    (11, ' Rendering', '2008-
    
    08-23', '20:55:12'),
    (12, 'Max scripts', '2008-08-23', '20:56:09'),
    (13, 'Architectural', '2008-08-23', '21:08:26'),
    (14, 
    
    'Hardware', '2009-02-13', '04:55:18'),
    (15, 'Other', '2009-02-13', '04:55:32'),
    (16, 'Plug-in', '2009-02-13', '05:12:35'),
    (17, 'Making of', '2009-02-13', '05:19:17'),
    (18, 'Texturing', '2009-02-14', '06:07:24'),
    (19, 'Particles', '2009-02-18', 
    
    '04:50:27'),
    (20, '3D Models', '2009-02-18', '06:47:13'),
    (21, 'RealFlow', '2009-02-18', '07:44:51'),
    (22, 'V-Ray', '2009-04
    
    -22', '03:24:41'),
    (23, 'Character Modeling', '2009-05-14', '08:57:31'),
    (24, 'Special FX', '2009-05-19', '10:43:48'),
    (25, 
    
    'Workflow', '2009-06-06', '10:07:33'),
    (26, 'Mental Ray', '2009-06-06', '22:38:22');
    
    Code (markup):
    Can some one help me out with this.

    With regards,
    Srinivas.
     
    3DCADForums, Sep 11, 2010 IP
  2. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #2
    $get_categories=mysql_query("SELECT * from resource_categories order by name ASC"); //note the where statement and not orderby. by using order by it will list only the first item
    while ($show_categories=mysql_fetch_array($get_categories))
    $name=$show_categories['name'];



    Should be

    $get_categories=mysql_query("SELECT * from resource_categories where id=$id_cat");
    while ($show_categories=mysql_fetch_array($get_categories))
    $name=$show_categories['name'];
     
    lowridertj, Sep 11, 2010 IP