Parsing arrays to another php-file?

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
StumpDK
Forum Commoner
Posts: 35
Joined: Thu Feb 12, 2004 2:28 am
Location: Copenhagen, Denmark

Parsing arrays to another php-file?

Post by StumpDK »

Hey there!
I have a html-page with a link to the same page (a sort-by-name-function). It shows a list of data from a database. My problem is, that every time I open the PHP-page the query will run again causing much action on my harddisk.
Is there anyway I can parse an array with the results from the database instead of running the database query again?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

how about [php_man]sort()[/php_man]
StumpDK
Forum Commoner
Posts: 35
Joined: Thu Feb 12, 2004 2:28 am
Location: Copenhagen, Denmark

Post by StumpDK »

I know Sort(). But I won't have any array to sort if I can't pass the array from show_my_list.php to show_my_sorted_list.php.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

why wouldn't you be able to pass it tot he other page?? use sessions. If you don't know anything about sessions then i suggest reading some tutorials.
StumpDK
Forum Commoner
Posts: 35
Joined: Thu Feb 12, 2004 2:28 am
Location: Copenhagen, Denmark

Post by StumpDK »

Thanks... I just didn't thought that sessions could parse arrays as well, but of course... Thank you...
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

parse arrays?? i dont understand. You dont use sessions to parse anything. I think you are confusing the words 'parse' and 'pass'. LOL
Danzig
Forum Newbie
Posts: 5
Joined: Fri Apr 02, 2004 6:24 am

Post by Danzig »

to pass an array from one php page to the other through POST/GET use serialize() and unserialize() functions. http://www.php.net/serialize for examples.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Danzig, you don't have to use serialize and unserialize, and the best way to pass an array would be to use Sessions...
Danzig
Forum Newbie
Posts: 5
Joined: Fri Apr 02, 2004 6:24 am

Post by Danzig »

I'll make this quick since i do not have much time.

Sessions are used to keep state between pages, this is mostly used for a login system. If you store login information such as username, user preferances ..etc then that information will be required across all pages of your site. Thus Sessions are used. Although Sessions can pass non-state information acorss pages, it was not meant to serve that purpose as it is not efficient and niether is it logical. Thats why the Serialize function has been made.

Serialize has been specifically made for one purpose and one purpose alone. To pass vars, arrays and objects from one page to the other. This is information that you will need in only one single page, which is what the poster of this question wanted.

Using sessions in this way is certainly not "the best way". Cars and planes can get you to your desired destination, but each one is used in different situations.
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

Global keyword works as well, to pass arrays around.
Post Reply