Solved

Smarty & PHP problem... cannot use $_GET[id]

Posted on 2007-12-05
19
377 Views
Last Modified: 2008-02-01
I am updating a clients existing site which uses PHP and smarty to handle some pages with the xcart excommerce system.

Basically i have done a listing of products and i now want to do some page navigation to get to pages 2, 3 etc etc.

Each of these page numbers links to an URL like -

index.php?cat=1234&page=3

My problem is i cannot for the life of me get $_GET[page] to give me the page number 3 so that i can then set my offset in my query.

I am doing my query in PHP and not smarty.

I'm new to smarty and tbh find it a bit of a headache. Can someone let me know how to get this very simple issue resolved? I must be missing a trick somewhere but it doesn't seem very obvious.

Cheers
0
Comment
Question by:Sailo100
  • 8
  • 5
  • 3
  • +1
19 Comments
 
LVL 5

Expert Comment

by:nacker2000
ID: 20414701
Hi,

It should be formatted like: $page = trim($_GET['page']); You missed off the quotes (assuming this isn't a typo)
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20414801
Can you give some example code?
As nacker2000 said, you probably missed off the quote.

As an example, this would work:

index.php?cat=1234&page=3

##index.php##
<?php
$page = $_GET["page"];
echo "The page variable is: " . $page;
//.. etc..
?>
0
 

Author Comment

by:Sailo100
ID: 20414936
It's a bit more complicated than that guys!

$_GET does not work at all.... it must be something to do with Smarty.

I have attached part of my code!

Also - $_GET[page] works perfectly well without quotes ;-)
{php}
 
$pagenav = "<div id=\"pagenav\" style=\"margin-top:5px; border:thin #CCCCCC;\">
			  <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"120\" align=\"center\">
  				<tr>";
$i = 0;
while ($i < $total_pages && $i < 10) {
	$pagenav .= "<td width=\"12\" align=\"left\"><a href=\"home.php?cat=$cat&pageno=".($i + 1)."\">".($i + 1)."</a></td>";
	$i++;
}
 
$pagenav .= "</tr></table></div>";	
 
echo $pagenav;
 
$page = $_GET[pageno];
 
echo "<br />page get - $page";
 
{/php}

Open in new window

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:Sailo100
ID: 20414948
I forgot to say $page at the end is always empty
0
 
LVL 5

Expert Comment

by:nacker2000
ID: 20414971
line 16 above, should be $page = $_GET['pageno'];
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20415115

<?php
 
$pagenav = "<div id=\"pagenav\" style=\"margin-top:5px; border:thin #CCCCCC;\">
                          <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"120\" align=\"center\">
                                <tr>";
$i = 0;
while ($i < $total_pages && $i < 10) {
        $pagenav .= "<td width=\"12\" align=\"left\"><a href=\"home.php?cat=$cat&pageno=".($i + 1)."\">".($i + 1)."</a></td>";
        $i++;
}
 
$pagenav .= "</tr></table></div>";      
 
echo $pagenav;
 
$page = $_GET["pageno"];
 
echo "<br />page get - $page";
 
?>

Open in new window

0
 
LVL 10

Expert Comment

by:wildzero
ID: 20415224
at the very top of your page, do this
  die(print_r($_GET));
if you see nothing there, try
  die(print_r($_REQUEST));

0
 

Author Comment

by:Sailo100
ID: 20415308
$page = $_GET["pageno"]; this is not the problem!

i have tried it with single, double quotes.....  its not the issue!!

die(print_r($_GET)); OR die(print_r($_REQUEST));

they just give me a number 1.

0
 
LVL 10

Expert Comment

by:wildzero
ID: 20415314
If you view the source code of it, was it just

1

or was there something else in there as well.
0
 

Author Comment

by:Sailo100
ID: 20415324
btw it might be relevant that this website is running with frames!
0
 

Author Comment

by:Sailo100
ID: 20415345
Just the number 1
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20415351
>>i have tried it with single, double quotes.....  its not the issue!!
It may not be the problem now, but you need to put the quotes in there as it will probably become the problem later on.

Frames may be causing the problem, can you get the 'cat' variable ok?
0
 
LVL 5

Expert Comment

by:nacker2000
ID: 20415356
Quick check, try
<?php
	if(isset($_GET['pageno'])){
		print('Page number set: ' . trim($_GET['pageno']));
	}else{
		print('Not set');
	}
?>

Open in new window

0
 
LVL 10

Expert Comment

by:wildzero
ID: 20415369
Is this page live on the net? Got a url? Wouldn't mind seeing request / response headers.

You could try putting
die(print_r($_GET)); OR die(print_r($_REQUEST));
in your frameset page (if it's PHP).

If you create a random file, like
testing.php
and inside there do
<?PHP
 print_r($_GET);
?>
then hit that in your browser
whatever.com/testing.php?sasdsasdf

does that show up?
0
 

Author Comment

by:Sailo100
ID: 20415556
i can only get the cat by using smarty code -

$cat = $this->get_template_vars('cat');

I have tried this but it does not work -

$page = $this->get_template_vars('pageno');

if i try $_GET['cat'] that does not work either.

I have tried a test.php file and that works as expected.

Are you familiar with smarty templates?
0
 
LVL 10

Accepted Solution

by:
wildzero earned 500 total points
ID: 20415578
Sooo.....

You are actually IN the template, not in the PHP file that controls the template?
You have to assign variables to the template, for the template to use.

ie
in the controlling php file there will be something like this
$template->assign('cat', 'A cat');
which is why it shows up in $this->get_template_vars('cat');

you will need to be assigning $_GET['pageno'] to 'pageno'  similar to how cat is done.
0
 

Author Comment

by:Sailo100
ID: 20415762
ok thats helped loads!  however, no i have a slightly different issue!

here is my url - home.php?cat=6052&test=1

if i echo $_GET['cat'] i get 6052&test=1

if i echo $_GET['test'] i get nothing

I could do a simple explode on this but it seems a little odd to go to these lengths.
0
 

Author Comment

by:Sailo100
ID: 20416443
I fixed the rest myself... i just needed a nudge in the right direction!

Thanks
0
 
LVL 10

Expert Comment

by:wildzero
ID: 20416449
Excellent :-)
Glade it sorted!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
reverse engineer .sql from php files 11 33
PHP alternative to file_get_contents('php://input') 4 53
Wordpress Pagination 1 28
PHP 5.6 and 7.x 4 20
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question