Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help on Passing big arrays to another page.

    Hi,

    I'm having a little problem on my advanced search system with large amounts of results, when trying to pass them to another page.

    Tried to use the serialize function but when the results reach a number, for instance, of 300 the link will not handle that. It works for small resultsets.

    Thanks in advance for any help or suggestion.

    Explaining:

    <!--### The Objective ###--->

    When user search the database for (example) stores in "New York" we get 256 results.
    Now I want to give the user the chance to search on these results, the stores found in the former query that sell "bread", which would take the user to another page called "advanced search for store features".

    This to avoid the use of big forms for these advanced searches, where I've created a degree set of search pages (I have about an overall 250 features to search).

    <!--### The Problem ###--->

    The main problem seems to pass the array to the other page when large ammounts of data are set on this array, which I'll call here as $storeIDs.

    When the results are small, the serialize and unserialize function will do the job.

    Is there a way of going through this in other manner?

    <!--### The Solution ###-->

    To be achieved...

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Err.. I think you left out the most interesting part... how you actually "pass" this voluminous array to the next page.

    Because you said that the "link" would not be able to handle it, I guess you're passing the serialized array by appending it to the link's URL like "?array=serializedArray" and retrieve it on the next page with unserialize($_GET) or something similar.

    So my first question would be: Why do you need to pass the whole array, which is a serialized form of the result set, at all to the next page?
    What I would do is pass the search parameters that defined the previous resultset and pass them as additional WHERE clauses to the SQL statement responsible for doing the search.

    So if your user searches on the first page for stores = bread, then you only need to pass this info to your next page, and so on, always narrowing down the result set with multiple where-statements.
    That's just how I would do it, in a rough sketch.

    Alternatively, you could also write the array data to a session and retrieve it's content later, or write it to temporary file of your choice or store the data in the database.

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Ye I was passing the serialized array through the link and that didn't work for the large amount of data.

    I need to pass the whole array, just because I would like to enable the user to search within the previous results, for example:

    The user has searched for "Stores" containing the name "Levis", which resulted on 256 results (store ID's).

    Now, I would like to enable the user to search for that same criteria - stores "Levis" on "New York" ($location), this is, using the array of the last search.

    This might seem easy, if we think on just this two variables, but in fact I've got about 225 choices for Advanced search.

    In order to overcome the handling of this ammount of choices, I've structured the search function on 4 categories (4 different pages - Search by name; Search by Feature, Search by location and Search by price).

    Probably this wasn't a good idea and I'm not confortable with the session stuff. I also could create a TEMP table on MySql, but That seems even harder for me to do.

    If it isn't asking to much, would you just give a simple example of how may I do it using sessions or TEMP tables. Then I would try to work it to suit my needs.

    Thanks in advance.

    MArioPro

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a small example how to use sessions in PHP:

    firstPage.php
    PHP Code:
    session_start();
    $myResultset= array("result1""result2""result3");

    //  add a variable to a session
    $_SESSION["resultset"] = $myResultset
    secondPage.php
    PHP Code:
    session_start();

    if (isset(
    $_SESSION["resultset"])) {
        echo 
    "<pre>";
        
    var_dump($_SESSION);
        echo 
    "</pre>";    

    This example just prints a dumped version of $_SESSION.

    You see that it's acutally not very difficult. You have to start a session with session_start() to initialize it, and then you have read/write access to the superglobal $_SESSION array. Additionally, you don't have to explicitly call serialize() when adding array or object data to a session.

    Note, however, that the above example expects a recent version of PHP (4.2) and a register_globals=Off configuration setting. Why this is important to check can be read on http://za2.php.net/manual/en/ref.session.php , the example code on this page could also help you getting started with sessions on your particular system.

    Let me still point out why I think that my approach would be IMHO more suitable for your needs (if I don't bore you ):

    1.) The array solution provides the user with a static search resultset. Whereas doing a new, "advanced" search by passing more values that have to match in WHERE parts of the SQL query always return a most recent resultset of your database.

    2.) If you have huge resultsets, as you indicated, your array to put into a session can get enormous and thus a recursive search on this array *might* reduce the script's performance. On the other hand, letting the search do the database is usually more efficient.

    just my 0.02 €

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for your tips.They are very helpfull.

    I tried to use the session functions and after making the first search, which gave results, I tried to make another different one and it seems that something was cahed, this is, I first searched for "Levis" and then for "MacDonnalds" and the displayed results were again for "Levis" ?!

    I'm now trying to build a new fresh script in order to avoid looping on the same errors over and over.

    MarioPro

  • #6
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mordred View Post
    Here's a small example how to use sessions in PHP:

    firstPage.php
    PHP Code:
    session_start();
    $myResultset= array("result1""result2""result3");

    //  add a variable to a session
    $_SESSION["resultset"] = $myResultset
    secondPage.php
    PHP Code:
    session_start();

    if (isset(
    $_SESSION["resultset"])) {
        echo 
    "<pre>";
        
    var_dump($_SESSION);
        echo 
    "</pre>";    

    This example just prints a dumped version of $_SESSION.

    You see that it's acutally not very difficult. You have to start a session with session_start() to initialize it, and then you have read/write access to the superglobal $_SESSION array. Additionally, you don't have to explicitly call serialize() when adding array or object data to a session.

    Note, however, that the above example expects a recent version of PHP (4.2) and a register_globals=Off configuration setting. Why this is important to check can be read on http://za2.php.net/manual/en/ref.session.php , the example code on this page could also help you getting started with sessions on your particular system.

    Let me still point out why I think that my approach would be IMHO more suitable for your needs (if I don't bore you ):

    1.) The array solution provides the user with a static search resultset. Whereas doing a new, "advanced" search by passing more values that have to match in WHERE parts of the SQL query always return a most recent resultset of your database.

    2.) If you have huge resultsets, as you indicated, your array to put into a session can get enormous and thus a recursive search on this array *might* reduce the script's performance. On the other hand, letting the search do the database is usually more efficient.

    just my 0.02 €
    I have read data from excel file into an array, I used your way to send data of this array to another page, but only send 52 lines of this array. I don't know how the error handling, could you suggest me a solution to this issue?

    Thank you!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •