0

我有一个重写的网址,显示为:

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

最后的数字是我需要在 mySQL 查询中使用以允许用户阅读这篇文章的 URL 变量 - 有没有办法使用 $_GET 或爆炸来获取这个数字,所以我可以用它来调出我的 mySQL 数据库中的文章正确吗?

这是我尝试过的,但它不起作用:

<?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);
?> 

我的网站目前正在运行,文章无法正常工作,因此您可以提供的任何帮助都非常棒!!!

4

1 回答 1

0
<?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 

?>
于 2012-05-24T05:51:39.627 回答