hello everyone plz help me out with this script.
I am calling my pages in this way in main page
if(isset($_GET['page'])=='view_user' && $_GET['page']=='view_user')include("user/crud_user.php");
i have user class in which i am doing pagination
$self = $_SERVER['PHP_SELF'];
if($this->openPage<=0) {
$next = 2;
}
else {
$next = $this->openPage+1;
}
$prev = $this->openPage-1;
$last = $this->pages;
if($this->openPage > 1) {
echo "<a href=$self?page=1>First</a>  ";
echo "<a href=$self?page=$prev>Prev</a>  ";
}
The url of the page which is using this class is lie this
admin.php?page=view_user
Now i can get pagination no according to the records but when i click on no it rather take me to admin.php?page=3 because of self . I want to stick to that page for showing the result . I tried in this way also $self="admin.php?page=view_user";but no luck . please help me out
To use one variable for serving two different purposes is quite unusual idea.
Let me suggest you to use 2 different variables, one to designate included page and another to point to the actual page in pagination.
Hope this helps.
do
if(isset($_GET['page']) && $_GET['page'] == 'view_user')
{
include("user/crud_user.php");
exit;
}
because of many reasons.
for pagination try the following: http://www.catchmyfame.com/2007/07/28/finally-the-simple-pagination-class/
Related
I am new to php, I need small help
I m creating a page in php named index.php
i want when someone view that page automatically a number or anything would be added to the url end
Like www.abc.com/index.php ---> www.abc.com/index.php?abc or ?132
when ever that index page is refreshed it should get a number or any variable in the end
Try this:
<?php
if (!isset($_GET["123"])) {
header("Location: " . $_SERVER["PHP_SELF"] ."?123");
}
$QS = $_SERVER["QUERY_STRING"];
$URL = "http://www.example.com/index.php";
// Check if Anything already assigned
if( empty($QS) ) {
// Generate Any RANDOM Number Here
$NUM = mt_rand(999, 9999);
// Reload Page and assign number
header("Location: {$URL}?{$NUM}");
}
Place this code in the very top of your page
Give this a go
<?php
$num = '123';
if(!isset($_GET[$num])){
header("Location: /path/to/page?$num");
}
my code is related to breadcrumbs.. that is it should display previous page or from where it is navigated and i achieved it partially , while im refreshing 2-3 times im getting the current page not the previous page.. so pl help me on this
my code lies in session.php as
$add = $_SERVER['PHP_SELF'];
if($_SESSION['pageadd'][1]!= $_SESSION['pageadd'][2])
{ $_SESSION['pageadd'][2]= $_SESSION['pageadd'][1];
}
echo $_SESSION['pageadd'][2];
if(($_SESSION['pageadd'][1]!= $add) )
{ $_SESSION['pageadd'][1]= $_SESSION['pageadd'][0];
$_SESSION['pageadd'][0]=$add;
}
What you want isn't a breadcrumb - it's a history for visited pages! This could be achieved with something like this:
if (!isset($_SESSION['pageadd'])) {
$_SESSION['pageadd'] = array();
}
// add page
$_SESSION['pageadd'][] = $_SERVER['PHP_SELF']
// only save last 5 pages
if (count($_SESSION['pageadd'])) > 5) {
array_shift($_SESSION['pageadd']);
}
Try to use $_SERVER['HTTP_REFERER'] it will return you previous url. However you need to store it in some hidden field or session like you are doing now.
Hope this help :)
I have an original link:
http://example.com/catalog/catagoryname/
When I click on 2-th page, url like this:
http://example.com/catalog/catagoryname/1
Ok, how to hide number of page in the end url ?
Best regards.
As far as I understand you don't want to have anywhere:
http://example.com/catalog/catagoryname/1 but http://example.com/catalog/catagoryname/ but you want to use urls with other numbers http://example.com/catalog/catagoryname/2, http://example.com/catalog/catagoryname/3 and so on. You don't need to do it in .htaccess. You should do it in your PHP code
Simple in place where you use pagination (you probably have loop for this), you should use condition:
for ($pageNr = 1; $pageNr < $totalPages; ++$pageNr) {
if ($pageNr == 1) {
echo 'http://example.com/catalog/catagoryname/';
}
else {
echo 'http://example.com/catalog/catagoryname/'.$pageNr;
}
}
Of course it's only sample, because you haven't put full code in your question
I'm working with a page that, once a link is called this script checks and if the POST contains the keyword it and then finds that page. However no matter how I organize this if it doesn't work.
<?PHP
if($_POST['page']) {
$page = (int)$_POST['page'];
$exists = file_exists('pages/page_'.$page.'html');
if($exists) {
echo file_get_contexnts('pages/page_'.$page.'html');
} else {
echo 'There is no such page!';
}
} else if ($_POST['course']) die("0"); {
$course = (int)$_POST['course'];
$exists = file_exists('courses/course_'.$course.'html');
if($exists) {
echo file_get_contexnts('courses/course_'.$course.'html');
die("1");
} else {
echo 'There is no such page!';
}
}
?>
The error I'm currently receiving with this setup is:
Notice: Undefined index: course in C:\wamp\www\Home Page\load_page.php on line 12
Call Stack
# Time Memory Function Location
1 0.0003 253944 {main}( ) ..\load_page.php:0
Is it because there is no 'course' in the page? I might be confused of the code I'm modifying a tutorial of a simple ajax website. It is possible what I am trying to do does not work.
In that case how could I possible go about doing what I want to do.
Right now I have a home page and it loads in another page without switching pages. I like the floridness of it. I would like to have a sort of sub call. So if you are on the home page and you go to courses page then you can click on a specific course and that will load from a different directory within the courses directory.
Homepage (when you click on courses you go to...)
pages/courses_home.html (when you click on a course you go to...)
courses/course_1.html (you can view course and then click back to directory above or go to home)
That is the structure I'm looking to try to achieve.
If more information is needed please let me know what and I'll do my best to include it. Thank you.
The syntax should be:
if(isset($_POST["page"])) {
} elseif(isset($_POST["course"])) {
}
I am not sure why you have a die statement there, but I don't think it belongs. Also, keep in mind the logic for what happens if neither of these conditions is met.
Edit: also keep in mind that isset doesn't prevent empty strings, so you may want to check for that as well. A function you could use is
function checkPost($value) {
return isset($_POST[$value]) && $_POST[$value] !== "";
}
To use:
if(checkPost('page')) {
//some logic
}
Wrong syntax.
elseif ($_POST['course']) {
without die statement.If 'course' undefined else statement works and does not get error. Sorry for bad English.
Try this:
if isset(($_POST['page'])) {
...
} else if isset(($_POST['course'])) die("0"); {
instead of this:
if($_POST['page']) {
...
} else if ($_POST['course']) die("0"); {
I've been trying to conditionally include a banner which incorporates a form into a php site. Previously the banner was part of the header but I need to exclude it from certain pages in order for other elements to be included.
I'm using $_SERVER['SCRIPT_NAME'] to define a variable on the page and then check for this. I'm a little confused though as to where the variable should be placed. Will it work if placed in the header or does it need to be included in every separate page?
This is what I've got:
<?php $currentPage = $_SERVER['SCRIPT_NAME']; ?>
<?php if ($currentPage != "/ecoProcess.php") {
include ("includes/banner.php");
} else {
echo "ECO";
}
?>
For further info, I've updated the code because of my schoolboy error with -= instead of != but neither of the conditions works now (no banner, no "ECO"). The pages are being called using this method:
<?php if($_GET['action']=='boiler_installation_replacement') {?> class="active"<? php } ?>>Boiler Installation and Replacement
I've been advised to try var_dump which reveals this:
' string(14) "/ths/index.php" ' everytime. I guess this is due to the way the pages are called but I don't know how to get around this.
-= means subtract right value from left side. Eg.
$a = 5;
$a -= 3;
echo $a; // will print 2 because 5 - 3 = 2 :)
Change it to comparison == or better ===. You can also use !=/ !== for opposite cases.
Change your condition like this.
<?php
$currentPage = $_SERVER['SCRIPT_NAME'];
if ($currentPage == "/ecoProcess.php") {
include ("includes/banner.php");
} else {
echo "ECO";
}
?>
Try this:
just change your if statement because it is not logically correct.
Use this
if ($currentPage == "/ecoProcess.php")
instead of
if ($currentPage -= "/ecoProcess.php")
Thanks