0

foreach ループとセッション変数を使用して生成された結果ページがあります。

これはそれがどのように見えるかです

<?php

  if(count($degree) > 0){
      foreach ($degree as $key => $val){
          $url = "http://www.concordiauniversity.com/".$val.'/'.$classname[$key];
          echo "<form method='post' enctype='multipart/form-data' action='/classname_handler'><div class='control-group' align='center'><ul class='thumbnails'><a href=$url class='thumbnail'><img src=$url onerror=this.src='images.png' alt=Click the empty space here to see the class :) width=60 height=100></a><h4>$classname[$key]</h4><a href='/classname_handler' type='text' id='follower' name='follower' class='btn btn-large btn-block btn-primary' type='button'>follow class <i class='icon-hand-right icon-white'></i> $val <i class='icon-user icon-white'></i></a></ul></div></form>";
          $_SESSION['degree'] = $degree;
          $_SESSION['classname'] = $classname;
      }
  }
  ?>

私の質問は、各 $classname に設定されたセッションを取得して、フォロークラスボタンをクリックしたときにセッションがその特定のクラス専用になるようにする方法です。私が今持っている方法では、配列が返されます。

4

3 に答える 3

0

ここで何をしようとしているのかは完全にはわかりませんが、セッション変数が反復ごとに上書きされていることを理解しています。次のようなものを使用します

  $_SESSION['degree'] = $degree;

  foreach ($degree as $key => $val){
      $url = "http://www.concordiauniversity.com/".$val.'/'.$classname[$key];
      echo " ..... ";
  }

次に、実際のクラスページでセッションを使用して値を取得します

$_SESSION['degree'][KEY_FROM_URL]
于 2013-03-21T00:14:47.430 に答える
0

内に多次元配列を作成できます$_SESSION

$_SESSION['degree'][] = $degree;
$_SESSION['classname'][] = $classname;
于 2013-03-21T00:13:32.913 に答える
0

答えは2つの答えの組み合わせであることがわかりました

$_SESSION['degree'] = $val;
$_SESSION['classname'] = $classname[$key];

ハンドラーの代わりに結果ページに!ありがとう!

于 2013-03-21T01:14:23.763 に答える