471,624 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

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_countries = mysql_query("SELECT COUNTRY_CODE, COUNTRY_$lang
FROM countries WHERE CONTINENT_CODE = $i ORDER BY COUNTRY_$lang ASC");
$j = 0;
while ($row = mysql_fetch_array($search_countries, MYSQL_NUM)) {
$countries[$j][0] = $row[0];
$countries[$j][1] = $row[1];
$key_country = $countries[$j][0];
$count_coasters_country = mysql_query("SELECT COUNT(*) FROM coasters
WHERE COUNTRY_CODE = '$key_country'");
$total_coasters_country = mysql_result($count_coasters_country,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?

Jul 21 '05 #1
7 8655

<be*****@coaster.ch> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I want to define an array bidimensional as a session array.
<?
$continents = array (1 => $europe, $america, $oceania, $africa, $asia);
$i = 1;
do {
$search_countries = mysql_query("SELECT COUNTRY_CODE, COUNTRY_$lang
FROM countries WHERE CONTINENT_CODE = $i ORDER BY COUNTRY_$lang ASC");
$j = 0;
while ($row = mysql_fetch_array($search_countries, MYSQL_NUM)) {
$countries[$j][0] = $row[0];
$countries[$j][1] = $row[1];
$key_country = $countries[$j][0];
$count_coasters_country = mysql_query("SELECT COUNT(*) FROM coasters
WHERE COUNTRY_CODE = '$key_country'");
$total_coasters_country = mysql_result($count_coasters_country,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?


Here is an shortened example of what I do.

<?php
$sel_users_query = "SELECT member.*, photosound.portrait " .
"FROM member, photosound " .
"WHERE member.username=photosound.username " .
"AND member.Age > 0";
mysql_select_db($database_ssLogin, $ssLogin);
$selResults=mysql_query($sel_users_query, $ssLogin)
or die(mysql_error());

$NumUsers = mysql_num_rows($selResults);
$dbResults = array();
for ($i=0; $i<$NumUsers; $i++) {
$row = mysql_fetch_assoc($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

Jul 21 '05 #2
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("search.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?

Jul 21 '05 #3

<be*****@coaster.ch> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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("search.php"). But it seems
that the programm makes the whole search once again every time I return
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.
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?

Jul 21 '05 #4
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.

Jul 21 '05 #5

<be*****@coaster.ch> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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.


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
Jul 21 '05 #6
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.

Jul 21 '05 #7

<be*****@coaster.ch> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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.


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

Shelly
Jul 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JLSSCH | last post: by
3 posts views Thread by klynn | last post: by
3 posts views Thread by Brad | last post: by
5 posts views Thread by Diffident | last post: by
4 posts views Thread by chrism | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.