Jump to content

Do you need an array when inserting multiple fileds in mysql dbase?


WesleyA

Recommended Posts

The idea is to insert with the browser a multiple input field, a loop, into mysql database.

 

Is the solution to first put this loop input variable in an array and after that create in this case multible tables?

 

Or is an array not necessary?

Link to comment
Share on other sites

Arrays are never really necessary, they just make it easier to deal with related data. Without an array you couldn't really use a loop, for example. If you want to do that in a loop then use an array.

Link to comment
Share on other sites

If its easier and you need it for a loop then I go fo the array.

 

I'm stuck with the following script.

     <?php     echo "<form method = 'POST' target = '_blank'>";		for($x = 0; $x < 5; $x++)		{			echo "<input type = 'text' name = 'runame' /></br>";		}		echo "<input type = 'submit' value = 'send' /> ";			echo "</from>";          ////         if (isset($_POST['runame']))  {         $runame = $_POST['runame'];		for($x = 0; $x < 5; $x++){		$test[$x] = array($runame => $x);											}									}      if (isset ($test)) {			echo "<pre>";			for($x = 0; $x < 5; $x++){			print_r($test[$x]);					}			echo "</pre>";					}         ?>

Only the last entry is taken. I also want the first four entries.

Link to comment
Share on other sites

You don't need for loop for print_r

 

You can have array within array as you original wanted with

        <?php        echo "<form method = 'POST' target = '_blank'>";        for ($x = 0; $x < 5; $x++) {            echo "<input type = 'text' name = 'runame[]' value='aaaa" . $x . "' /></br>";        }        echo "<input type = 'submit' value = 'send' /> ";        echo "</from>";        if (isset($_POST['runame'])) {            $runame = $_POST['runame'];            for ($x = 0; $x < 5; $x++) {                $test[$x] = array($runame[$x]);            }        }        if (isset($test)) {            echo "<pre>";            //for ($x = 0; $x < 5; $x++) {            print_r($test);            // }            echo "</pre>";        }        ?>

or one single array, but you would get same result just with print_r($runame); without adding to another array that is storing the same values.

    <body>        <?php        echo "<form method = 'POST' target = '_blank'>";        for ($x = 0; $x < 5; $x++) {            echo "<input type = 'text' name = 'runame[]' value='aaaa" . $x . "' /></br>";        }        echo "<input type = 'submit' value = 'send' /> ";        echo "</from>";        if (isset($_POST['runame'])) {            $runame = $_POST['runame'];            for ($x = 0; $x < 5; $x++) {                $test[$x] = $runame[$x];            }        }        if (isset($test)) {            echo "<pre>";            //for ($x = 0; $x < 5; $x++) {            print_r($test);            // }            echo "</pre>";        }        ?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...