?
Solved

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

Posted on 2007-12-05
19
Medium Priority
?
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …
Suggested Courses

801 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