|
Posted by Shelly on 07/19/05 20:50
<bettina@coaster.ch> wrote in message
news:1121793777.724894.95940@f14g2000cwb.googlegroups.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
[Back to original message]
|