Help me with dinamic Title?

I writed SQL like:

– phpMyAdmin SQL Dump
– version 2.7.0-pl2
http://www.phpmyadmin.net

– Host: localhost
– Generation Time: Mar 13, 2012 at 03:58 AM
– Server version: 5.0.18
– PHP Version: 5.1.2

– Database: example



– Table structure for table products

CREATE TABLE products (
id int(10) NOT NULL auto_increment,
name varchar(25) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


– Dumping data for table products

INSERT INTO products VALUES (1, ‘Computer’);
INSERT INTO products VALUES (2, ‘Telephone’);

And 2 file:
1. index.php
<?php
$host=“localhost”;
$username=“root”;
$password=“”;
$db_name=“example”;
$con = mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);

$tbl_name=“products”;
mysql_select_db(“$db_name”)or die(“Eror…”);
$sql=“SELECT * FROM $tbl_name”;
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count<>0)
{

  while($row=mysql_fetch_assoc($result))
  {
	$id=$row[id];
	$name=$row[name];
	echo"&lt;li&gt;&lt;a href='test.php?t=".$id."'&gt;$name&lt;/a&gt;&lt;/li&gt;";			

  }

}
else
{
echo"Product is zero";
}
?>

2. test.php
<?php
$host=“localhost”;
$username=“root”;
$password=“”;
$db_name=“example”;
$con = mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);

$t=$_REQUEST[“t”];
$tbl_name=“products”;
mysql_select_db(“$db_name”)or die(“Eror…”);
$sql=“SELECT * FROM $tbl_name”;
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count<>0)
{

  while($row=mysql_fetch_assoc($result))
  {
	$id=$row[id];
	$name=$row[name];
	
	if($t==$id)
	{
	echo"$name&lt;/li&gt;";			
 	}
  }

}
else
{
echo"Product is zero";
}
?>

I want to when click link “Computer”,“Telephone” on file index.php.
and file : test.php will change title like : “Computer”,“Telephone”

HELP ME!
Thanks Everyone… :slight_smile:

I suggest you alter your MySQL query in test.php, to only grab the record you want (such as SELECT * FROM products WHERE id = 1). You will then have just one row, so you won’t need to loop over it, just grab that row the same way as you were, without the while loop ($row=mysql_fetch_assoc($result)), then pop it in to the $name and $id variables as before.

You can then use that variable around the page…


<html>
<head>
<title><?php echo $name; ?></title>
</head>
<body>
<h1><?php echo $name; ?></h1>
<p>...</p>
</body>
</html>

Okie, Thanks You very much !!!