hriti 0 Light Poster

hello
i have a problem
if anyone can solve it please help me...
i have a page from which i get type on left side of page from refrence page...and when i click any one of the reference it shows list on same page regarding to that reference
when i click on particular reference it will go to next page.. on next page i want same refrences on left side according to type...
my problem is it shows all the references in table

my code for reference page is:

<?php include("include/connection.inc.php");
session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lumex LED Lights</title>

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container" align="center">
<div id="wrapper" align="center">
<div align="center"><img src="images/wrappertop.png" width="1004" height="19" /></div>
<div class="CL"></div>
<div class="logo lfloat"><img src="images/logo.png" /></div><div class="search rfloat">
 <script>
  (function() {
    var cx = '013580470917512101672:0ssj6ajuova';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
</div>
<div class="CL" style="height:40px; background:url(images/head_seperator.png) center bottom repeat-x; width:996px;"></div>

<div id="nav"><div class="nav lfloat" align="left">
<ul><li style="width:80px;" ><a href="index.php"><img src="images/home_icon.png" border="0" /></a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="profile.php">Company Profile</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:150px;"><a href="lighting_fundamentals.php">Lighting Fundamentals</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="products.php">Products</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="references.php">References</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="#">Contact Us</a></li></ul>
</div>
</div>
<div class="CL"></div>

<div class="sidebarpanel lfloat">
<div id='cssmenu' class="lfloat">
 <?php $q="SELECT * FROM ref_type ORDER BY id";
        $output=mysql_query($q) or die (mysql_error().$q);
          while ($rows=mysql_fetch_array($output)){
          ?>  
<ul>
   <li><a href='references.php?post_id=<?php echo $rows['id'];?>'><span><?php echo $rows['ref_type'];?></span></a></li>
   </ul>
   <?php } ?>
</div>
</div>
<div class="fundamentalsarea lfloat">
<?php 
$post_id=$_GET['post_id'];
$q="SELECT * FROM ref_type where id='$post_id' ORDER BY id";
        $output=mysql_query($q) or die (mysql_error().$q);
          while ($rows=mysql_fetch_array($output)){
          ?>  
<div class="producthead lfloat"><?php echo $rows['ref_type'];?></div>
<?php } ?>
<div class="CL"></div>
<div class="productlistbase lfloat effect6">
<div class="referencetopic lfloat">
<?php 
$post_id=$_GET['post_id'];
$q="SELECT * FROM refrences where ref_type='$post_id' ORDER BY id";
        $output=mysql_query($q) or die (mysql_error().$q);
          while ($rows=mysql_fetch_array($output)){
          ?>
<ul>
<li><a href='reference_topic.php?p_id=<?php echo $rows['id'];?>'><?php echo $rows['title'];?></a></li>
</ul>
<?php } ?>
</div>
</div>
</div>
<div class="CL" style="height:40px;"></div>

<div align="center"><img src="images/wrapperfooter.png" /></div>
</div>
<div class="CL" style="height:40px;"></div>
<div class="footer">Copyright &copy; 2013-14, Lumax Red Lights. All Rights Reserved.</div>
</div>
</body>
</html>

and for refrence_topic.php is:

<?php include("include/connection.inc.php");
session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lumex LED Lights</title>

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container" align="center">
<div id="wrapper" align="center">
<div align="center"><img src="images/wrappertop.png" width="1004" height="19" /></div>
<div class="CL"></div>
<div class="logo lfloat"><img src="images/logo.png" /></div><div class="search rfloat">
  <form id="form1" name="form1" method="post" action="">
    <div class="lfloat"><label for="textfield"></label>
    <input name="textfield" type="text" class="searchfield" id="textfield" onclick="this.value='';" value="Search your Keyword" /></div><div style="position:relative; float:left; left:2px; margin:4px;">
    <input type="image" src="images/search_button.png" name="button" id="button" value="Submit" style="margin:0px;" /></div>
  </form>
</div>
<div class="CL" style="height:40px; background:url(images/head_seperator.png) center bottom repeat-x; width:996px;"></div>


<div id="nav"><div class="nav lfloat" align="left">
<ul><li style="width:80px;" ><a href="index.php"><img src="images/home_icon.png" border="0" /></a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="profile.php">Company Profile</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:150px;"><a href="lighting_fundamentals.php">Lighting Fundamentals</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="products.php">Products</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="references.php">References</a></li><li><img src="images/nav_seperator.png" /></li><li style="width:110px;"><a href="#">Contact Us</a></li></ul>
</div>
</div>
<div class="CL"></div>

<div class="sidebarpanel lfloat">
<div id='cssmenu' class="lfloat">
<?php  $post_id=$_GET['post_id'];
        $q="SELECT * FROM refrences where id='$post_id' ORDER BY id";
        $output=mysql_query($q) or die (mysql_error().$q);
        while ($row=mysql_fetch_array($output)){
          ?>

<ul>
   <li><a href='reference_topic.php?p_id=<?php echo $row['id'];?>&post_id=<?php echo $post_id;?>'><?php echo $row['title'];?></a></li>
  </ul>
  <?php } ?>
</div>
</div>

<div class=" productrightpanel lfloat">

<div class="producthead lfloat">Projects</div>

<div class="CL" style="height:20px;"></div>
<?php  $p_id=$_GET['p_id'];
        $q="select * from refrences WHERE id = '$p_id' ORDER BY id";
        $output=mysql_query($q) or die (mysql_error().$q);
        while($rows=mysql_fetch_array($output)){
          ?>
<div class=" productname lfloat"><?php echo $rows['title'];?></div>
<div class="CL"></div>
<div class=" productsubdetails lfloat"><?php echo $rows['detail'];?></div>
<?php } ?>
</div>


<div class="CL" style="height:40px;"></div>

<div align="center"><img src="images/wrapperfooter.png" /></div>
</div>
<div class="CL" style="height:40px;"></div>
<div class="footer">Copyright &copy; 2013-14, Lumax Red Lights. All Rights Reserved.</div>
</div>
</body>
</html>

please help me if anyone understand my problem...
thanks in advance...