Hello,

I am trying to get values from a session into a array, this let me set my posted values back to my select-form. The user can set up a ranking from illustrations.
What goes wrong?
When i set up a echo i will get back: 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Top of page:

<?
session_start();

include('connect.php');

$link = dbconnect();
$arr = "". $_SESSION["illustrations"];
$array = explode(";",$arr);

for($i=0; $i < count($array); $i++)
{
$iv = explode(":",$array[$i]);

$idvalue[$iv[0]] = $iv[1];

echo $iv[1];

}
?>

body:

echo "<tr><td><img src=\"../stijlen/".$row["filename"]."\"><td>"."</td></tr></table></td><table></tr>\n";
echo "<tr><td><select name=\"I".$row["illustrations_id"]."\" size=\"1\">";

    if( in_array("I".$row["illustrations_id"], $iv ) ) echo " selected";

    if( in_array("I".$row["illustrations_id"], $idvalue ) ) echo " selected";

    for($i=0; $i<6; $i++)
    {
        if( in_array("I".$row["illustrations_id"], $iv ) ) echo " checked";

        echo "<option value='$i' $i>$i</option>";
    }
    echo "</select></td></tr>\n";

Please help!

    Echo $illustrations out as well. Looking at the code it must be what's actusally in there that is causing the problem.

      $illustrations is not the problem. The problem is in the array, i just started with arrays...

      Somebody can help?

        I believe you may be trying to set up multi-dimensional arrays in your for loop. Here is a simplified model that I think may help:

        <?php
        // $arr = id number: rating relationships
        $arr = '1:2; 2:4; 3:5; 4:5; 5:8; 6:6; 7:0; 8:0; 9:2; 10:6';
        
        // explode into pairs of id:value
        $array = explode(';',$arr);
        
        for($i=0; $i < count($array); $i++){
            // explode again into distinct id to value
            $iv[$i] = explode(':', trim($array[$i]));
            $idnumber[$i] = $iv[$i][0]; // number
            $idvalue[$i] = $iv[$i][1]; // rating value
            // print results
            echo 'ID: ' . $idnumber[$i] . ', Rating: ' . $idvalue[$i] . '<br />' . "\n";
        
        }
        ?> 
        

        I hope that I understand you correctly and that this helps a little. (I know it is way simplified...)

          I get the following printed values

          ID: I123, Rating: 4
          ID: I124, Rating: 3
          ID: I125, Rating: 5
          ID: I126, Rating: 1
          ID: I127, Rating: 0
          ID: I128, Rating: 5
          ID: I129, Rating: 0
          ID: I130, Rating: 0
          ID: I131, Rating: 0
          ID: I132, Rating: 0
          ID: I133, Rating: 0
          ID: I134, Rating: 0
          ID: I135, Rating: 0
          ID: I136, Rating: 0
          ID: I137, Rating: 0
          ID: I142, Rating: 0

          I can't get them in my selectboxes. That's my whole problem.

          My complete code is:

          <?
          session_start();

          include('connect.php');

          $link = dbconnect();
          $arr = "". $_SESSION["illustrations"];
          $array = explode(";",$arr);
          $iv = explode(":",$array[$i]);

          for($i=0; $i < count($array); $i++)
          {
          $iv = explode(":",$array[$i]);
          $idnumber[$i] = $iv[$i][0];
          echo $iv[1];
          }

          for($i=0; $i < count($array); $i++){
          $iv[$i] = explode(':', trim($array[$i]));
          $idnumber[$i] = $iv[$i][0];
          $idvalue[$i] = $iv[$i][1];

          echo 'ID: ' . $idnumber[$i] . ', Rating: ' . $idvalue[$i] . '<br />' . "\n";

          }

          ?>

          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

          <html>

          <head>
          	<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
          	<meta name="generator" content="Adobe GoLive 6">
          	<title>Hipidee</title>
          	<link href="hipidee.css" rel="stylesheet" media="screen">
          </head>
          
          <body background="../gfx/bgbloem.gif" bgcolor="#ffffff" leftmargin="30" marginheight="30" marginwidth="30" topmargin="30">
          	<table width="480" border="0" cellspacing="0" cellpadding="0">
          		<tr>
          			<td><b>
          					<form action="stap5_basic.php" method="post" name="FormName">
          						<img src="../gfx/titel_stap4.gif" alt="" height="43" width="470" border="0"><b><br>
          							<span class="tekst">Kies maximaal 5 illustraties. Geef de illustraties een </span><span class="tekst"><b>cijfer van 1 tot 5</b></span><b><span class="tekst">,<b> waarin cijfer <b>5</b> de </span></b><span class="tekst"><b>meest favoriete illustratie</span><span class="tekst"> <b>is. </b><br>
          								<br>
          								<table width="100%" border="0" cellspacing="0" cellpadding="0">
          									<?

          $query = "SELECT illustrations_id, filename FROM binary_data WHERE style_id=1";
          $result = @($query);

          if($result)
          {
          while ($row = mysql_fetch_array($result))
          {

              echo "<tr><td><img src=\"../stijlen/".$row["filename"]."\"><td>"."</td></tr></table></td><table></tr>\n";
              echo "<tr><td><select name=\"I".$row["illustrations_id"]."\" size=\"1\">";
              echo $idvalue[$i];
              for($i=0; $i<6; $i++)
              {
          
          
              if( in_array("I".$row["illustrations_id"], $idvalue[$i] ) ) echo " selected";
          
              if( in_array("I".$row["illustrations_id"], $idvalue ) ) echo " selected";
          
              for($i=0; $i<6; $i++)
              {
                  if( in_array("I".$row["illustrations_id"], $idvalue[$i] ) ) echo " checked";
          
                  echo "<option value='$i' $i>$i</option>";
              }
          
              }
          }

          }

          ?>
          <tr>

          										<td><a href="stap3_basic.php"><img src="../gfx/knop_terug.gif" alt="" height="28" width="25" border="0"></a></td>
          										<td></td>
          										<td></td>
          										<td>
          											<div align="right">
          											<br>
          												<br><td>
          												<img src="../gfx/knop_vooruit.gif" alt="" height="28" width="25" border="0" onclick="submit();" style="cursor:hand;"></div></td>
          										</td>
          									</tr>
          
          								</table>
          							</span></b>
          					</form>
          				</b></td>
          		</tr>
          	</table>
          </body>

          </html>
          <?

          mysql_close($link);

          ?>

          Somebody know's the problem?

          Thank's

          Sander

            Write a Reply...