• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

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

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
Sailo100
Asked:
Sailo100
  • 8
  • 5
  • 3
  • +1
1 Solution
 
nacker2000Commented:
Hi,

It should be formatted like: $page = trim($_GET['page']); You missed off the quotes (assuming this isn't a typo)
0
 
nizsmoDeveloperCommented:
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
 
Sailo100Author Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Sailo100Author Commented:
I forgot to say $page at the end is always empty
0
 
nacker2000Commented:
line 16 above, should be $page = $_GET['pageno'];
0
 
nizsmoDeveloperCommented:

<?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
 
wildzeroCommented:
at the very top of your page, do this
  die(print_r($_GET));
if you see nothing there, try
  die(print_r($_REQUEST));

0
 
Sailo100Author Commented:
$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
 
wildzeroCommented:
If you view the source code of it, was it just

1

or was there something else in there as well.
0
 
Sailo100Author Commented:
btw it might be relevant that this website is running with frames!
0
 
Sailo100Author Commented:
Just the number 1
0
 
nizsmoDeveloperCommented:
>>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
 
nacker2000Commented:
Quick check, try
<?php
	if(isset($_GET['pageno'])){
		print('Page number set: ' . trim($_GET['pageno']));
	}else{
		print('Not set');
	}
?>

Open in new window

0
 
wildzeroCommented:
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
 
Sailo100Author Commented:
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
 
wildzeroCommented:
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
 
Sailo100Author Commented:
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
 
Sailo100Author Commented:
I fixed the rest myself... i just needed a nudge in the right direction!

Thanks
0
 
wildzeroCommented:
Excellent :-)
Glade it sorted!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now