how to open all links in one page

Discussion in 'PHP' started by snowLee, Jun 23, 2009.

  1. #1
    I have on my side bar links. I want when I click on each link to open each page in the same one, which is the blog.php. I tried, but I guess I'm missing something because doesn't work. I need a little help.
    This is my code, with the blog.php, where I have the side bar:
    <?php
            include ('mysql_connect.php');
    		
            $query = "SELECT id, title, author,post,category, DATE_FORMAT(date, '%M %d, %Y') as sd  FROM news_posts ORDER BY date DESC";
            $result = @mysql_query($query); 
            if ($result) 
    	{
              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    	 {   
              $mess = stripslashes($row['post']); 
              echo '<p class="text"><b><a href="article.php?id='.$row['id'].'">'. $row['title'].'</a></b><br />'. $row['sd'].'<br />
    		  Category: <b>'.$row['category'].'</b><br />
    		  Posted by: <b>'.$row['author'].'</b><br />';
    		  
              echo snippet($mess, 200, true);
              echo "</p>"; 
              }
            }  
    	else 
    	{  
              echo 'There are no news posts to display';
            } 
            ?>	
    		
            </div>	
            <div id="sidebar">  
    	   <div id="top_sidebar">								
               
              <?php
               $cat = $_GET['category'];
    	   $query = "SELECT id, title, author,post,category FROM news_posts WHERE category='cat'";
    	   $result = @mysql_query($query);
    	   if ($result){
    		$count_items = count($result);
    		$cat = $row['category'];
                    echo '<a href="blog.php?cat=css">CSS</a>';				
    	    }  
    			?>
    		  </div>		
            </div>
    PHP:

     
    snowLee, Jun 23, 2009 IP
  2. adfly

    adfly Active Member

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    88
    #2
    I'm not sure what exactly you are trying to do, but I think the problem is here -

    <?php
    $cat = $_GET['category'];
    $query = "SELECT id, title, author,post,category FROM news_posts WHERE category='cat'";
    $result = @mysql_query($query);
    if ($result){
        $count_items = count($result);
        $cat = $row['category'];
        echo '<a href="blog.php?cat=css">CSS</a>';        
    }  
    ?>
    Code (markup):
    This will only echo out one link multiple times (<a href="blog.php?cat=css">CSS</a>). Should it possibly be -

    <?php
    $cat = $_GET['category'];
    $query = "SELECT id, title, author,post,category FROM news_posts";
    $result = @mysql_query($query);
    if ($result){
        $count_items = count($result);
        $cat = $row['category'];
        echo '<a href="blog.php?cat='.urlencode($cat).'">'.$cat.'</a>';        
    }  
    ?>
    Code (markup):
     
    adfly, Jun 24, 2009 IP