Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Quick Question

  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Quick Question

    Hi, I currently have a script for my news, the PHP file is this:

    PHP Code:
    <?php
           
        $amount_get 
    mysql_query("SELECT * FROM comment WHERE articleid='" mysql_real_escape_string($_GET['id']) . "'"); $comments mysql_num_rows($amount_get);
           
            
    $grab mysql_query("SELECT * FROM articles WHERE id='" mysql_real_escape_string($_GET['id']) . "' LIMIT 1");
            
            
    $article $row['news_title'];
            
        if (
    mysql_num_rows($grab)==0) {
            
            die();
        }
        
            while(
    $row mysql_fetch_array($grab)){
            
            
    ?>
    <p></p>
    <div class="container">
      <div class="header"><?php echo $row['news_title'?></div>
      <div class="content"><?php echo $row['news_content'?></div>
      <div class="comments"> <a href="<?php echo $row['id'?>">Comments (<?php echo $comments ?>)</a> </div>
      <div class="posted"> <i> Posted by <strong><?php echo $row['news_author'?></strong> on <strong><?php echo $row['news_date'?></strong> </i> </div>
    </div>

            <?php ?>

    <div class="container">
      <div class="header_comments">Article Comments</div>
      
      <?php

    $name 
    mysql_real_escape_string($_POST['name']);
    $comment mysql_real_escape_string($_POST['comment']);
    $submit $_POST['submit'];
    $date date("y-m-d");
    $ip "".$_SERVER['REMOTE_ADDR']."";

    if(
    $submit)
    {
        if(
    $name&&$comment)
        {
        
        
    $query=mysql_query("
        
        INSERT INTO comment (id, articleid, name, comment, date, ip) VALUES ('','"
    mysql_real_escape_string($_GET['id']) ."','$name','$comment','$date','$ip')
        
        "
    );
        
    header("Location: " mysql_real_escape_string($_GET['id']) . "");
        
        }
        else
        {
            echo 
    "<div class='red'>You must fill in all fields!</div>";
        }
    }
    ?>

            <?php
           
        $amount_get 
    mysql_query("SELECT * FROM comment WHERE articleid='" mysql_real_escape_string($_GET['id']) . "'"); $comments mysql_num_rows($amount_get);
           
        
    $grab mysql_query("SELECT * FROM comment WHERE articleid='" mysql_real_escape_string($_GET['id']) . "'");
        
        if (
    mysql_num_rows($grab)==0) {
            
            echo 
    "<p> There are no comments to be displayed! </p>";
        }
        
            while(
    $row mysql_fetch_array($grab)){
            
            
    ?>
      
      <div class="grey">
      
      Posted by <strong><?php echo $row['name'?></strong> on <strong><?php echo $row['date'?></strong>
      
      <br /><br />
      
      <?php echo $row['comment'?>
      
      </div>
      
      <div class="grey_line"></div>
           
           <?php ?> 
           
           <a href="../comment.php" rel="facebox">Post Comment</a>
      
    </div>

    </body>
    </html>
    <?php ob_flush(); ?>

    Now, this is my .htaccess:
    Code:
    RewriteEngine On 
    RewriteRule ^article/(.*)/?$ article/article.php?id=$1 [L,QSA]
    the finished product would look like this: article/5 or article/6 based on what my articles are.

    Now I'm simply trying to add a "article/ID.ARTICLE-NAME-HERE", how would I go about doing this? Is it a PHP file problem, or a .htaccess problem?

    Thank you for your time!

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    You can do it both either with web server rewrite:

    Code:
    RewriteEngine On 
    RewriteRule ^article/([0-9]+).*/?$ article/article.php?id=$1 [L,QSA]
    or with php and your rewrite:

    PHP Code:
    preg_match('/^([0-9]+)/'$_GET['id'], $match);
    $id $match[1]; 
    Last edited by poyzn; 11-08-2012 at 05:53 AM.

  • Users who have thanked poyzn for this post:

    Sniickerz (11-08-2012)

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks man, I appreciate you!

    I'll have to add the ID.ARTICLE-NAME after it in the URL, but it still works!


  •  

    Posting Permissions

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