Advertisement

11.01.2007 at 12:05PM PDT, ID: 22933187
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

help to delete from array

Asked by shang3000 in PHP Scripting Language

Tags: , , ,

hi  all,
I want to make generator for form fields so that I can add/delete/update  tables, and in each table I can add/delete/update fields.
it works fine tell I try to delete the last field in the table it does not  responde and I don't know why also I done some tracing it confuse me

now my question is can you please help me to make it work just fine?

thanks in advance
best regards
HG


here is the code:
<?php
/*
echo "<pre>";
print_r ($_REQUEST);
echo "</pre><br />";
*/

if (isset($del_table))
{
      $del_table= str_replace("del table","",$del_table);
      echo($del_table);
}


if (isset($add_field))
{
      $add_field= str_replace("add field","",$add_field);
      echo($add_field);
}

if (isset($del_field))
{
      $del_field= str_replace("del field","",$del_field);
      echo($del_field);
}
?>

<form name="f" method="post" action="load.php">
<input name="add_table" type="submit" value="add table" /> <br />


<?php
      $table_name=$_REQUEST['table_name'];
      
      if(isset($del_table))
      {
            array_splice($table_name,$del_table,1);
      }
      //print_r($table_name);

      for($x=0; $x < count($table_name); $x++)
      {
?>
            table:<input name="table_name[]" type="text"
            value="<?php echo $table_name[$x];?>" />
                        
            <input  name="del_table" type="submit"
                  value="del table<?php echo $x;?>" />

            <input  name="add_field" type="submit"
                  value="add field<?php echo $x;?>" />
            <br />
            
            <?php
            $fields[$x]= $_REQUEST["field$x"];
            
            

            if(isset($del_table))
            {
                  array_splice($fields,$del_table,1);
            }
            if (isset($add_field))
            {
                  $add_field= str_replace("add field","",$add_field);
                  $pieces= explode ("_", $add_field);
                  
            }

            

            if(isset($fields[$x]))
            {
                  $tmp=$fields[$x];
                  echo "count of tmp ". count($tmp);
                        echo "<pre>";
                        print_r ($fields[$x]);
                        echo "</pre><br />";

                  for($y=0; $y < count($tmp); $y++)
                  {
                        
                        if(isset($del_field))
                        {
                              $pieces= explode ("_", $del_field);
                              
                              if($pieces[0]==$x and $pieces[1]==$y )
                              {
                                    if (count($tmp<=1))
                                    {
                                          unset($tmp);
                                    }
                                    else
                                    {
                                    array_splice($tmp,$pieces[1],1);
                                    }      
                                    
                              }
                              $fields[$x]=$tmp;
                        }
                        
                        
            ?>
                        &nbsp;&nbsp;&nbsp;&nbsp;field<input name="field<?php echo $x; ?>[]" type="text" value="<?php echo $tmp[$y]?>" />
                        <input  name="del_field" type="submit"
                              value="del field<?php echo $x."_".$y;?>" />
                        <br />            

            <?php
                  }
            }      
            ?>

            <?php
            if (isset($add_field))
            {
                  if($add_field==$x)
                  {
            ?>
            &nbsp;&nbsp;&nbsp;&nbsp;field<input name="field<?php echo $x; ?>[]" type="text" value="" />
            <input  name="del_field" type="submit"
                              value="del field<?php echo $x."_".$y;?>" /><br />            
            <?php
                  }
            }
            ?>

<?php
      }
?>


<?php
if ($_REQUEST['add_table']=="add table")
{
?>
      table:<input name="table_name[]" type="text" />
       
<br />
<?php
}
?>

</form>Start Free Trial
 
 
[+][-]11.01.2007 at 12:44PM PDT, ID: 20196004

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: array, php, delete, from
Sign Up Now!
Solution Provided By: NickVd
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.01.2007 at 06:06PM PDT, ID: 20197735

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.02.2007 at 08:40AM PDT, ID: 20201869

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11.03.2007 at 02:42AM PDT, ID: 20206374

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.04.2007 at 11:20PM PST, ID: 20214357

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628