473,856 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

Jul 21 '05 #1
7 8779

<be*****@coaste r.ch> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
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?


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

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("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?

Jul 21 '05 #3

<be*****@coaste r.ch> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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("s earch.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*****@coaste r.ch> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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*****@coaste r.ch> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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
2029
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 on a non-object. I have session.autostart turned off, and I have the class definition for those objects included before the call to session_start(). I am on PHP 4.2.3. Is this possible to do? While debugging, it appears that the objects in...
0
1436
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 problem i that the value appears to be lost when I redirect from the page defined the string array in to another page. The script language I am using is JavaScript. _Page1.asp_
3
4190
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 an expression of type 'object'. Then, later, I try to use it, and sort on it an get 'cannot convert from 'object' to System.array. what am I doing wrong here?
3
2342
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() = DirectCast(Session("EventTypes"), String()) If Date.Today <= closeDate Then If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = Session("JRFee") Else thisFee = Session("PEFee") Else If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee =
5
3887
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 code below... Array declaration: DateTime DateRangesForDataLists = new DateTime;
4
159466
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: session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc'));
2
2990
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 standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
4
1655
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 set (plus table header). My problem is that I do not know how to pass the details of each record to an array session variable, once the form is submitted, and subsequently write all of this info to a dB. I have no problem doing this when there...
4
6278
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 so, set up variables: $name = $_POST; $ribbon = $_POST;
0
9906
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7929
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5757
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4171
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.