Array defined as SESSION Array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bettina@coaster.ch

    Array defined as SESSION Array

    I want to define an array bidimensional as a session array.
    <?
    $continents = array (1 => $europe, $america, $oceania, $africa, $asia);
    $i = 1;
    do {
    $search_countri es = mysql_query("SE LECT COUNTRY_CODE, COUNTRY_$lang
    FROM countries WHERE CONTINENT_CODE = $i ORDER BY COUNTRY_$lang ASC");
    $j = 0;
    while ($row = mysql_fetch_arr ay($search_coun tries, MYSQL_NUM)) {
    $countries[$j][0] = $row[0];
    $countries[$j][1] = $row[1];
    $key_country = $countries[$j][0];
    $count_coasters _country = mysql_query("SE LECT COUNT(*) FROM coasters
    WHERE COUNTRY_CODE = '$key_country'" );
    $total_coasters _country = mysql_result($c ount_coasters_c ountry,0,0);
    $countries[$j][2] = $total_coasters _country;
    $countries[$j][3] = $i;
    $j = $j + 1;
    }
    $i = $i + 1;
    } while ($i < 6 );

    $_SESSION["paises"] = $countries; Here I assign my array from 147 rows
    and 2 columns (1st column for code, 2nd column for name)to a session
    array.

    But now I don't know how to make a reference to each individual
    element, as I would do with the original array countries, for example:
    $country[0][1],$country[2][1], etc.

    How should I do?

  • Shelly

    #2
    Re: Array defined as SESSION Array


    <bettina@coaste r.ch> wrote in message
    news:1121793777 .724894.95940@f 14g2000cwb.goog legroups.com...[color=blue]
    >I want to define an array bidimensional as a session array.
    > <?
    > $continents = array (1 => $europe, $america, $oceania, $africa, $asia);
    > $i = 1;
    > do {
    > $search_countri es = mysql_query("SE LECT COUNTRY_CODE, COUNTRY_$lang
    > FROM countries WHERE CONTINENT_CODE = $i ORDER BY COUNTRY_$lang ASC");
    > $j = 0;
    > while ($row = mysql_fetch_arr ay($search_coun tries, MYSQL_NUM)) {
    > $countries[$j][0] = $row[0];
    > $countries[$j][1] = $row[1];
    > $key_country = $countries[$j][0];
    > $count_coasters _country = mysql_query("SE LECT COUNT(*) FROM coasters
    > WHERE COUNTRY_CODE = '$key_country'" );
    > $total_coasters _country = mysql_result($c ount_coasters_c ountry,0,0);
    > $countries[$j][2] = $total_coasters _country;
    > $countries[$j][3] = $i;
    > $j = $j + 1;
    > }
    > $i = $i + 1;
    > } while ($i < 6 );
    >
    > $_SESSION["paises"] = $countries; Here I assign my array from 147 rows
    > and 2 columns (1st column for code, 2nd column for name)to a session
    > array.
    >
    > But now I don't know how to make a reference to each individual
    > element, as I would do with the original array countries, for example:
    > $country[0][1],$country[2][1], etc.
    >
    > How should I do?
    >[/color]

    Here is an shortened example of what I do.

    <?php
    $sel_users_quer y = "SELECT member.*, photosound.port rait " .
    "FROM member, photosound " .
    "WHERE member.username =photosound.use rname " .
    "AND member.Age > 0";
    mysql_select_db ($database_ssLo gin, $ssLogin);
    $selResults=mys ql_query($sel_u sers_query, $ssLogin)
    or die(mysql_error ());

    $NumUsers = mysql_num_rows( $selResults);
    $dbResults = array();
    for ($i=0; $i<$NumUsers; $i++) {
    $row = mysql_fetch_ass oc($selResults) ;
    $dbResults[$i]['username'] = $row['username'];
    $dbResults[$i]['LastName'] = $row['LastName'];
    $dbResults[$i]['FirstName'] = $row['FirstName'];
    $dbResults[$i]['portrait'] = $row['portrait'];
    }
    $_SESSION['NumUsers'] = $NumUsers;
    $_SESSION['dbResults'] = $dbResults;
    ?>

    <?php

    and then in the other file I have:

    $NumUsers = $_SESSION['NumUsers'];
    $dbResults = $_SESSION['dbResults'];
    for ($i=$list_start ; $i<$NumUsers; $i++) {
    echo $dbResults[$i]['username'] . " " . $dbResults[$i]['LastName'] . ", "
    ..
    $dbResults[$i]['FirstName'] . " " . $dbResults[$i]['portrait'] =
    $row['portrait'];

    }
    ?>

    Hope that helps. This works great for me.

    Shelly



    Comment

    • bettina@coaster.ch

      #3
      Re: Array defined as SESSION Array

      I've tried something similar to what you made, but the website is still
      too slow.
      The first php file where you charge the array and then assign it to a
      session array will be executed only once? I've called it search.php and
      then in the main file I wrote include_once("s earch.php"). But it seems
      that the programm makes the whole search once again every time I return
      to the main file. It's worth to mention that I have 147 countries, from
      each I have to count the coasters, Totally I have 11505 coasters... I
      don't know how long it can take to charge all the information.... If
      you want, you can have a look at my home page www.coaster.ch and tell
      me if it's really too slow.
      I tried taking out the quantity of coasters, that's to say the query
      where they will be counted and it 's rapid, but in such a why I would
      lose important information.
      Any idea?

      Comment

      • Shelly

        #4
        Re: Array defined as SESSION Array


        <bettina@coaste r.ch> wrote in message
        news:1121800699 .274740.162640@ f14g2000cwb.goo glegroups.com.. .[color=blue]
        > I've tried something similar to what you made, but the website is still
        > too slow.
        > The first php file where you charge the array and then assign it to a
        > session array will be executed only once? I've called it search.php and
        > then in the main file I wrote include_once("s earch.php"). But it seems
        > that the programm makes the whole search once again every time I return[/color]

        Of course. include put in the in-line code. So if your search.php does the
        search, it will do it every time where it is included.

        What you want is to do the search, create the array, and then pass the array
        to a page that does the work and is re-entered. That way the driver,
        search.php, executes only once.
        [color=blue]
        > to the main file. It's worth to mention that I have 147 countries, from
        > each I have to count the coasters, Totally I have 11505 coasters... I
        > don't know how long it can take to charge all the information.... If
        > you want, you can have a look at my home page www.coaster.ch and tell
        > me if it's really too slow.
        > I tried taking out the quantity of coasters, that's to say the query
        > where they will be counted and it 's rapid, but in such a why I would
        > lose important information.
        > Any idea?
        >[/color]


        Comment

        • bettina@coaster.ch

          #5
          Re: Array defined as SESSION Array

          I want to understand exactly how it functions:
          Include_once search.php means that it will be included only once in
          index.php (supposing that index,php calls search.php.

          But what happens if I leave index.php, go for example to a subpage and
          come back again to index.php? Include_once will be executed again? I
          think so.
          I tried with a control question ...if (!isset($myvar) make the
          search.... It seems to work a little bit quickly.

          Comment

          • Shelly

            #6
            Re: Array defined as SESSION Array


            <bettina@coaste r.ch> wrote in message
            news:1121848541 .353870.213250@ g47g2000cwa.goo glegroups.com.. .[color=blue]
            >I want to understand exactly how it functions:
            > Include_once search.php means that it will be included only once in
            > index.php (supposing that index,php calls search.php.
            >
            > But what happens if I leave index.php, go for example to a subpage and
            > come back again to index.php? Include_once will be executed again? I
            > think so.
            > I tried with a control question ...if (!isset($myvar) make the
            > search.... It seems to work a little bit quickly.
            >[/color]

            The include_once means that the inline code is included only one time, even
            if it is included as part of another code. In that sense it is the same as
            the #include formulations in C, where each piece is given a name and you has
            the include stuff inside an #ifndef statement.

            What do you mean by "subpage". A page calls another page. When it comes
            back the original page is executed so the include_once stuff, while included
            only once, is re-executed. That is why putting inside the if (!isset
            bybasses the reselect.

            Shelly


            Comment

            • bettina@coaster.ch

              #7
              Re: Array defined as SESSION Array

              Yes, index is the main page (home) where the include_once is called. A
              subpage is a page that is linked to index. When I come back from the
              subpage to index unless I put this "if (!isset...) the include will be
              executed again.

              Comment

              • Shelly

                #8
                Re: Array defined as SESSION Array


                <bettina@coaste r.ch> wrote in message
                news:1121852444 .027412.198990@ g44g2000cwa.goo glegroups.com.. .[color=blue]
                > Yes, index is the main page (home) where the include_once is called. A
                > subpage is a page that is linked to index. When I come back from the
                > subpage to index unless I put this "if (!isset...) the include will be
                > executed again.
                >[/color]

                If it didn't without the if (!isset...), that would be incorrect.

                Shelly


                Comment

                Working...