I get errors: Notice: Undefined index: p, page, srt and where
// set default pagenation values
if(!$_GET['p']) $_GET['p'] = $conf['perpage']; // default number of entries per page
if(!$_GET['page']) $_GET['page'] = 1; // current page
if(!$_GET['srt']) $_GET['srt'] = $conf['srt']; // default sort order
$start = ($_GET['page'] - 1) * $_GET['p']; // start row for query
// get total number of entries for pagenation
$result = mysql_query("SELECT COUNT(*) FROM articals $where", $link);
$total = mysql_fetch_array($result); $total = $total[0]; // total number of listings
$pages = ceil($total / $_GET['p']); // number of pages
And also on: Notice: Undefined index: category, description,model,cond,location,photos,featured and where
$_GET = safe_data($_GET, 'query');
if($_GET['category']) $where .= "AND (category='$_GET[category]' OR category2='$_GET[category]') ";
if($_GET['description']) $where .= "AND description LIKE '%$_GET[description]%' ";
if($_GET['model']) $where .= "AND model LIKE '%$_GET[model]%' ";
if($_GET['cond']) $where .= "AND cond='$_GET[cond]' ";
if($_GET['location']) $where .= "AND location='$_GET[location]' ";
if($_GET['photos']) $where .= "AND images>'0' ";
if($_GET['featured']) $where .= "AND featured='1' ";
// finialize query string if necessary
if(substr($where, 0, 3) == 'AND') {
$where = ltrim($where, 'AND');
$where = 'WHERE'.$where;
}
// do not show hidden and expired listings
$display = "hide!='1' AND (expire>'".time()."' OR expire='' OR expire='0') AND (user_expire>'".time()."' OR user_expire='' OR user_expire='0')";
$display = "hide!='1'";
if(!$where) $where = "WHERE ".$display;
else $where .= "AND ".$display;
Any Help please?
In your URL, do you have parameters such as http://www.yoursite.com/yourpage.php?p=XXX&page=YYYY&srt=ZZZZ ?
If those parameters are optionnal, use:
if (!isset($_GET["p"])) $_GET["p"] = $conf["perpage"];
But actually, a better practice is to not assign $_GET by yourself. Instead, set a variable and use it later instead of using $_GET content:
$p = (isset($_GET["p"])?$_GET["p"]:$conf["perpage"]);
If you are doing a redirection in your htaccess, make sure to forward the GET parameters using [QSA].
You have to wrap isset()
Around every get request to get rid of the notice.
The Notice is shown because their is no value.
You can use it like this: if(isset($_GET['p']))
This code might help you, it wraps the http php response:
class Input {
public static function Post($item,$default=null){
//If the value was posted, then return that value, else return the $default value.
return isset($_POST[$item]) ? $_POST[$item] : $default;
}
public static function Get($item,$default=null){
return isset($_GET[$item]) ? $_GET[$item] : $default;
}
public static function Cookie($item,$default=null){
return isset($_COOKIE[$item]) ? $_COOKIE[$item] : $default;
}
public static function Param($item,$default=null){
return self::Post($item) ?: self::Get($item) ?: self::Cookie($item) ?: $default;
}
}
usage:
Input::Get('p',$conf['perpage']); // First argument is the index, second is default if not set.
in your example:
$p = Input::Get('p',$conf['perpage']);
$page = Input::Get('page',1);
$srt= Input::Get('page',$conf['srt']);
$start = ($page - 1) *$p; // start row for query