Set variables valid for several pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hector
Forum Newbie
Posts: 4
Joined: Fri Aug 19, 2005 10:01 am

Set variables valid for several pages

Post by Hector »

Comunity,

After 1 month of hart work, I just have bumped into a simple problem I dont know to resolve. I just need to set a variable and be able to use its value in other pages. For example if $variable1 = "sing" I would need to use that value in other pages ( of course $variable1 change depending of a form ).

My problem is that I only know to use variable values from one page to an other using $_POST or $_GET , and only form the first page to a second one, if I need this value in a third page, I lost it, so I need to know how to set a variable to use in other pages or how can I do to keep the value introduced in a form in more than a second page?.

Target: resolve the paginate problem in a search form. When the page show registers not coming form a previous form, pagination work perfectly, is when I .

I get the first result page correctly, with the right number of pages, but when you click the second or subsequent pages, the query doesnt run.

Here the code:

Code: Select all

$nombre_campo = strip_tags(trim($_POST['nombre_campo']));	
$edad_campo1 = strip_tags(trim($_POST['edad_campo1']));	
$edad_campo2 = strip_tags(trim($_POST['edad_campo2']));
$pais_campo = $_POST['pais_campo'];
$ciudad_campo = strip_tags(trim($_POST['ciudad_campo']));
$sexo_campo = $_POST['sexo_campo'];
$peso_campo1 = $_POST['peso_campo1'];
.......

Code: Select all

/* ############ */
CONNECTION
/* ############ */

/inicializo el criterio y recibo cualquier cadena que se desee buscar
$criterio = "";
if ($_GET["criterio"]!="")
{
	$txt_criterio = strip_tags(trim($_GET["criterio"]));	
	$criterio = " where ( nombre like '%".$txt_criterio."%'	OR anuncio like '%".$txt_criterio."%' OR edad like '%".$txt_criterio."%' OR aficcion like '%".$txt_criterio."%' 
	OR detesta like '%".$txt_criterio."%' OR peso like '%".$txt_criterio."%')";
}

//Limito la busqueda
$TAMANO_PAGINA = 4;

//examino la página a mostrar y el inicio del registro a mostrar
$pagina = $_GET["pagina"];
if (!$pagina) 
{
		$inicio = 0;
		$pagina = 1;
}
else
{
	$inicio = ($pagina - 1) * $TAMANO_PAGINA;
}	
		
	if ($orden_campo = '1')
	{			
	$sql = "SELECT ..... THE QUERY
        }
/* ############ */
SHOW OF DATA
/* ############ */

f ($total_paginas > 1)
{
	for ($i=1;$i<=$total_paginas;$i++)
	{
		if ($pagina == $i)
		{
			// si muestro el índice de la página actual, no coloco enlace
			echo $pagina . " ";
		}
		else
		{
			//si el índice no corresponde con la página mostrada actualmente, coloco el enlace para ir a esa página
			echo "<a href='rdo_busqueda.php?pagina=" . $i . "&criterio=" . $txt_criterio . "'>" . $i . "</a> ";
		}	
	}	
}
--------------------------------------------------------------------------------

The first page show the first registers correctly, and the number of total pages.

It is here when return to href='rdo_busqueda.php and the variables
$nombre_campo, $edad_campo1 , ... has no value, as there is nothing coming from any form.

Sorry to my long explanation, I have tried to describe my problem the best way.

I would thanks if anybody could help me.


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Have you read about "Sessions"? They can be used to do exactly what you're asking.
Hector
Forum Newbie
Posts: 4
Joined: Fri Aug 19, 2005 10:01 am

I dont know how to use session variables

Post by Hector »

Thanks to your prompt reply.

I have never use sessions variables and I dont know how to use it, and to be sincere, all the PHP programm language I have learned from the book ( PHP & MySQL for Dummies ) and getting deep into the problems I have found along my web, solving all problems myself, as I guess you all too, avoiding the web site http://www.php.net , the only reference to get information about, which I find extremely difficult, with bad explanations useless for non professional people, and impossible examples to follow.

Would you get any web, or an easy explanation to know the use of sessions variables.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

So your book doesn't cover session variables at all? I'm surprised.

I know you said you don't like the php.net site, but perhaps you can try reading
session_start

I've looked around for a few web tutorials, but all the ones I remembered were gone....
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Zend has session-tutorial: http://www.zend.com/zend/tut/session.php

You will have to get used to reading the PHP manual - once you're more familiar with PHP it will become easier and, eventually, second nature to you to read and understand it.
Hector
Forum Newbie
Posts: 4
Joined: Fri Aug 19, 2005 10:01 am

Thank you, I would try to get information about session v

Post by Hector »

Thank you, I would try to get information about session variables
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Re: I dont know how to use session variables

Post by Skittlewidth »

Hector wrote: avoiding the web site http://www.php.net , the only reference to get information about, which I find extremely difficult, with bad explanations useless for non professional people, and impossible examples to follow.
Wow, I always thought PHP had the best reference website of all the scripting languages I've looked at, even when I was a programming newbie I found it indispensible and its available in so many different lanaguages too...
Hector
Forum Newbie
Posts: 4
Joined: Fri Aug 19, 2005 10:01 am

I am not the only who find PHP net too difficult

Post by Hector »

I will not explain why PHP. NET is not a right place for newbies, and too precise in their information which become useless when you dont have solid knowledge about PHP. Of course you can try to explain the speed with examples describing the light-speed, but it is quite more helpfull to give examples concerning the concapt described, better than use complicated language and complicated examples which use the concepts treated in long and complicated big examples. Thats my point of view , and do not feel stupid at all.

:lol:
Post Reply