SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod_rewrite question: $_GET isn't pulling the right parameter

    Hi all,

    I'm using mod rewriting to clean up my urls. It goes to the page just fine, but it's not reading the query string parameters correctly.

    Here's my .htaccess
    Code:
    RewriteEngine On
    RewriteRule news/([_a-zA-Z0-9]+)/([_0-9]+)$ news.php?state=$1&newsItem=$1 [L]
    the top on news.php:

    PHP Code:
    if($_GET)
    {
        
    $statename $_GET['state'];
        
    $news_ID $_GET['newsItem'];
    }

    //Start Queries
    $state_sql "SELECT state_id, statename, stateabbr FROM states WHERE statename='$statename' ";

    $st_result mysql_query($state_sql);
    $st_row mysql_fetch_assoc($st_result);

    $state_ID $st_row['state_id'];
    $statename $st_row['statename'];
    $stateabbr $st_row['stateabbr'];

    //Query News
    $sql "SELECT news_id, a.art_id, a.title, a.body, a.hidden, UNIX_TIMESTAMP(a.created) created, UNIX_TIMESTAMP(a.modified) as modified, users.fname, users.lname FROM news_article_state as nas ";
    $sql .= "LEFT JOIN articles as a ON a.art_id=nas.art_fk ";
    $sql .= "LEFT JOIN users ON users.user_id=nas.user_fk ";
    $sql .= "WHERE nas.news_id = '$news_ID'";
    echo 
    $sql
    newsItem isn't being read correctly as when I echo out $news_ID it gives me the value in $_GET['state'] instead of the value in $_GET['newsItem'].

    The mod_rewritten address is domain.com/news/State/1
    the actual page without the mod_rewrite is news.php?state=State&newsItem=1

    I hope that's clear, any help would be much appreciated.

    Thanks!
    No, I REALLY dislike having to use Joomla.

  2. #2
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And after a little more googling, I found it.

    new .htacess

    Code:
    RewriteRule news/([_a-zA-Z0-9]+)/([_0-9]+)$ news.php?state=$1&newsItem=$2 [L]
    the second $1 was changed to $2...

    doh.
    No, I REALLY dislike having to use Joomla.

  3. #3
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)


    Since we're here:

    Code php:
    if($_GET) 
    { 
        $statename = mysql_real_escape_string($_GET['state']); 
        $news_ID = mysql_real_escape_string($_GET['newsItem']); 
    }
    Saul

  4. #4
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php_daemon,

    thanks for the pointer. May I ask why there and not in the query? Or does it not really matter?

    yay...#500!
    No, I REALLY dislike having to use Joomla.

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It doesn't really matter. But it makes more sense as you won't have to break the query string apart to use the function, and you're defining those variables before hand anyway.

    Congrats on 500
    Saul


Bookmarks

Posting Permissions

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