我有一个重写的网址,显示为:
http://www.coverforce.com.au/insurance-news/news/start-your-own-business-insurance/800479715/
最后的数字是我需要在mySQL查询中使用的URL变量,以允许用户阅读本文 - 是否有办法使用$ _GET或explode来获取此数字,以便我可以使用它在我的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);
?>
我的网站目前正在播放,且文章无法正常运行,因此您提供的任何帮助都会令人惊叹!
答案 0 :(得分: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
?>