Solved

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

Posted on 2007-12-05
19
369 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now