简体   繁体   中英

get value from rewritten url in php for a mysql query

I have a rewritten url that appears as:

http://www.coverforce.com.au/insurance-news/news/start-your-own-business-insurance/800479715/

The number on the end is the URL variable that I need to use in my mySQL query to allow the user to read this article - is there a way to use $_GET or explode to obtain this number so I can use it to bring up the correct article in my mySQL database?

This is what I have tried but it's not working:

<?php require_once('../Connections/newsDBconnection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$totalRows_variablearticles = "-1";
if (isset($_GET['id'])) {
  $totalRows_variablearticles = $_GET['id'];
}
mysql_select_db($database_newsDBconnection, $newsDBconnection);
$query_variablearticles = sprintf("SELECT * FROM NewsArticles, NewsArticleCategories, NewsArticlePhotos, NewsPhotos, NewsCategories WHERE NewsArticles.id = %s AND NewsArticles.id = NewsArticleCategories.newsArticleID AND NewsArticles.id = NewsArticlePhotos.newsArticleID AND NewsArticlePhotos.newsPhotoID = NewsPhotos.id AND NewsArticleCategories.newsCategoryID = NewsCategories.id", GetSQLValueString($totalRows_variablearticles, "int"));
$variablearticles = mysql_query($query_variablearticles, $newsDBconnection) or die(mysql_error());
$row_variablearticles = mysql_fetch_assoc($variablearticles);
$totalRows_variablearticles = mysql_num_rows($variablearticles);
?> 

My website is live at the moment and the articles aren't working so any help you can provide would really be AMAZING!!!

<?php

$Path = 'http://DomainName/news/articles/8008280';

//To get the innermost value  your id '8008280'

$Innermost = basename(rtrim($Path, '/'));

echo $Innermost; //will display '8008280'

// you can use article no for your query

// but make sure that article no is within the range of article no's in DB 

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM