473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 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 8750

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: college | last post by:
I am trying to pass an array of user objects in session and take the array out of session and call the member functions of each object. However I am getting a Fatal error: Call to a member function...
0
by: JLSSCH | last post by:
I am having trouble retrieving the value of a Session variable that ha a string array (the same problem occurs if I use a numeric array stored in it when I redirect from one page to another. The...
3
by: klynn | last post by:
I defined a session variable as an array using Session = new string; Later, in my code, I need to set it and sort it. I tried Session = "some string"; My error is "Cannot apply indexing with to...
3
by: Brad | last post by:
I am storing an array which contains about a dozen chracter items to a Session variable. Later, I need to use this array so I am doing the following: Dim eventTypes As String() =...
5
by: Diffident | last post by:
Hello All, I have a 2-dimensional array that I am storing as a session variable. I have no idea on how I can cast the session variable back to 2-dimensional array. Any pointers? Reference...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
4
by: sjohnson1984 | last post by:
Hello all, I have a form which is generated using a database query - the recordset is filled with agent details, login time and the like, and there are as many rows in the table as records in the...
4
by: chrism | last post by:
Hello, I'm hoping someone can help me out here. I'm building a shopping cart using sessions, populating with $_POST values from a form. Code abbreviated below: check if form is submitted. if...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.