Hello again,

I am having a hard time trying to get a values from my array. I have an array called ven. This array is created from form inputs and has a variable key. Look at the following to see how I am doing this:

while ($row = mysql_fetch_assoc($result))
		{
		echo "<TR valign='top'><td class='content'><input type='radio' name='application[".$i."]' value='appr - ".$row['app_id']."'></td><td class='content'><input type='radio' name='application[".$i."]' value='rej - ".$row['app_id']."'></td><td class='content'><font size='-1'><input type='text' name='ven[".$row['app_id']."]'</font></td><td class='content'><font size='-1'>".$row['user_owner']."</font></td><td class='content'><font size='-1'>".$row['app_access_for']."</font></td></tr>";
		$i++;
		}

on the action page I step through the application array, assign variables and perform a couple different queries.

$array = $_GET['application'];
	foreach($array as $value)
		{
		$dash_loc = strpos($value, '-');
		$total_len = strlen($value);
		$app_id = substr($value, $dash_loc + 1, $total_len);
		$action = substr($value, 0, $dash_loc - 1);
		$ven_num = $_GET['ven'];


	if ($action == 'appr')
		{
		$query2 = "select a.user_owner, a.uid, b.app_access_for from eCom_users a, eCom_approval b where a.uid = b.app_uid and b.app_id = '".$app_id."'";
		$result2 = mysql_db_query($db,$query2,$connection) or die (mysql_error());
		$query = "update eCom_approval set app_granted_on = '".date('Y-m-d')."', app_granted_by = '".$_SESSION['uid']."' where app_id = '".$app_id."'";
		$result = mysql_db_query($db,$query,$connection) or die (mysql_error());
		while ($row = mysql_fetch_assoc($result2))
			{
			echo "<font class='content' color='green'>Access has been granted for ".$row['user_owner']." to  ".$ven_num["$app_id"]."<BR>";
			//$query3 = "insert into eCom_logs (uid, log_message) values ('".$row['uid']."', 'access for ".$row['app_access_for']." granted by admin ".$_SESSION['uid']."')";
			//$result3 = mysql_db_query($db,$query3,$connection) or die (mysql_error());
			//$query4 = "update ecom_users set user_access = '".$_GET[$app_id]."' where uid = '".$row['uid']."'";
			//$result4 = mysql_db_query($db,$query4,$connection) or die (mysql_error());
			}
		}
	}

When I try to echo $ven_num["$app_id"] I get nothing. How can I do this? I have also tried $ven_num[$app_id] and $ven_num['$app_id'] with no avail.

    First, make sure that $app_id has a value, then make sure $ven_num as an index that corresponds to the value of $app_id.

    If you don't get a value from $ven_num[$app_id], then one of those things, or maybe something else as well, is wrong.

    You should find your problem.

      $app_id is the key and the value is what the user inputs into the field on the form. $app_id does have a value but when I put it in like you stated I get nothing. I will continue looking.

      Also is I put the value that the variable contains instead of using the variable I get a result.

      $ven_num = $_GET['ven'];
      $ven_num2 = $ven_num[20];
      
      echo $ven_num2; // Gives me the correct value
      

        Then $ven_num[$app_id] doesn't have a value.

        Do a print_r($ven_num) in your script to see what keys do exist.

          See above edit. I explain that is does have a value.

          Array ( [5] => [6] => [18] => [20] => admin [22] => [23] => [24] => [25] => )

            What about:

            $app_id = 20;
            $ven_num = $_GET['ven'];
            
            echo $ven_num[$app_id];

              Interesting, that works. I had the script echo the $app_id and it was set to 20 as well. Why won't it work in my code? is there something weird when using the for each loop?

                I figured it out, I added the app_id column to the $query2 statement and was able to use $ven_num[$row['app_id']] to get what I needed. Thanks for the help.

                  Write a Reply...