Jump to content

Archived

This topic is now archived and is closed to further replies.

smetal

Multi-Dimensional Session Arrays

Recommended Posts

I am a bit confused when it comes to these session arrays. I am new to session arrays as well as PHP, but I do pick up quickly. I am developing something where I need save a few variables into a session so I can use them on one page that can be universal. First, I go to a page and it will display all malls within a certain region. Then if you click on that store I want it to list all the stores within that one mall. I am using a mysql database. Here is where I'm stuck, I can get it to work when only one mall shows up in the region, but if it is let's say three malls that show up it will only save off the information on the last mall. When I looked at my code I realized that it was overwriting the variable with the last mall listed. I believe I need to create a multi-dimensional array something like $_SESSION['ID']['name'] My question is how do you store values in that [ID] and can it be a number? Also, on the universal page I want to be able to easily parse through it using something like $ID++ is this possible??? What I mean by universal page is just using one php page to query the database for the right information based on what mall the user clicks on. So for example, a user is on the southwest region page and all of the malls in the southwest region are listed. Then when the user clicks on the 3rd mall listed, it will take them to this "universal page" that will display all stores within the 3rd mall by running a query that uses the mall's ID key. Like I said, I have got it to work when there is just one Mall listed within that region, but if there are 4 listed the "universal page" will only display the store in mall 4. I hope this is clear enough. The code below will display the malls within the region.
[code] 
$count = 1;
while ($row= mysql_fetch_array($result)) {
  echo "$count.)";
  echo "<br />";
  $intersection = $row["INTERSECTION"];
  $name = $row["NAME"];
  $ID = $row["ID"];
  $_SESSION['s_intersection'] = $intersection;
  $_SESSION['s_name'] = $name;
  $_SESSION['s_ID'] = $ID;
          echo "$name";
          echo "$intersection";
  echo '<a href="http://www.mydomain.com/stores.php">See Stores</a>';
          $count ++;
}
[/code]

This code will store the session variables and then run a query based on the ID. Here is where I can only get it to work with one mall.
[code]
        $name = $_SESSION['s_name'] ;
$intersection = $_SESSION['s_intersection'] ;
$ID = $_SESSION['s_ID'] ;

mysql_connect($hostname,$username, $password) OR DIE (mysql_error());
mysql_select_db($dbname) OR DIE (mysql_error());

  $query = "select * from `TABLE` where `ID` LIKE \"%$ID%\"";
  $result = mysql_query($query) or die("Couldn't execute query");

[/code]
I need to be able to retreive data from all malls, but have this script run only when one is clicked.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.