Page 1 of 1

Dynamic vars

Posted: Mon Jun 05, 2006 4:13 am
by aetoc
How can i create dynamic vars in php?

Posted: Mon Jun 05, 2006 4:18 am
by jayshields
You haven't given much information, I can only presume you are talking about variable variables.

Posted: Mon Jun 05, 2006 4:29 am
by aetoc
Sorry.

I'm sending n vars from page1 to page2.

I want to use this vars in page2.

Ex.

$var1
$var2
$var3
...

Posted: Mon Jun 05, 2006 5:03 am
by aerodromoi
aetoc wrote:Sorry.

I'm sending n vars from page1 to page2.

I want to use this vars in page2.

Ex.

$var1
$var2
$var3
...
You'll have to tell us what $var contains (integer, string...)

Just a few ideas:
sessions: http://de.php.net/manual/en/ref.session.php
$_GET/$_POST: http://php3.de/manual/en/language.varia ... efined.php

aerodromoi

Posted: Mon Jun 05, 2006 5:57 am
by aetoc
Strings. I'm looking somthing like....

while (...)
{
echo $test.$counter;
$counter++;
}



P.S. Are you from Greece?

Posted: Mon Jun 05, 2006 6:01 am
by twigletmac
You will probably want sessions (if you don't want users to be able to adjust the value) so best to start where aerodromoi suggested:
http://php.net/manual/en/ref.session.php

Mac

Posted: Mon Jun 05, 2006 6:11 am
by aerodromoi
aetoc wrote:Strings. I'm looking somthing like....

while (...)
{
echo $test.$counter;
$counter++;
}



P.S. Are you from Greece?
So we're talking about passing $test (string) from page a to page b so that it can be printed out.
If it's a short string and this string has no changing effect on the state of the world ;) you can append it to the url.

Code: Select all

echo "<a href="page2.php?test=".$test."">page2</a>"; //for page 1

Code: Select all

$test = $_GET['test']; // for page 2
However, I'd recommend a regex match in order to check whether the input is correct. What other criteria does $test have?

If you're using a form, you could post $test via a hidden input field. However, if you're trying to pass on a variable which should not be changed by the user (accidentally or not), you should use sessions.

aerodromoi

ps: Not really, though my nick lends itself to that conclusion. Though I'd love to be there right now ;)

Posted: Tue Jun 06, 2006 2:28 am
by aetoc
twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


No. I wont to pass 1 to n vars from page a to page b.

The pass is going like this....

Code: Select all

while (($file2 = readdir($open_folder)) !== false)
  {
  if ($file2 != "." AND $file2 != ".." AND $file2 != "Thumbs.db")
    {
    if ($_POST['change'.$file_id] == "on")
      {
      $url .= "&files".$file_to."=".$file_id;
      $to_used[$file_to] = $file2;
      $file_to++;
      }
    $file_id++;
    }
  }
The $url have the currnetUrl.

It work's but I cant use the vars in the page b.

P.S. Sorry for my english. I know that they are not perfect.


twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]