Solved

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

Posted on 2007-12-05
19
375 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crazy text will not be removed no matter what I try! 13 30
php simple error message 4 23
Loop through multiple arrays 13 29
google analytics in wordpress 4 35
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

810 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