Jdizzleextreme
asked on
Create an Array, echo the results of the array
Hello experts,
"...And by the way, I'm new at programming."
I created a PHP/MySQL/Javascript file. The javascript allows a user to dynamically add more form select elements. The select fields are dynamically populated by a MySQL database, using PHP. I want to create an array of the select forms, so I can echo out all of the values associated with them.
Here is my basic code:
So, for instance, the user clicks "add". An identical form element to the one above is created dynamically. I want to be able to increase the name of the form element by one, each time a user clicks the "add" button. So, if the first select element's name is "name", then when the user clicks on the "add" button to add another select element, its name becomes "name-1". If the user clicks on the "add" button again, then the select element's name becomes "name-2".
How would I determine how many elements a user added and how would I echo out all of their values??
"...And by the way, I'm new at programming."
I created a PHP/MySQL/Javascript file. The javascript allows a user to dynamically add more form select elements. The select fields are dynamically populated by a MySQL database, using PHP. I want to create an array of the select forms, so I can echo out all of the values associated with them.
Here is my basic code:
<select style="width: 300px" name="" id="name">
<?php while($row = mysql_fetch_array($result)){
?>
<option value="<?php echo $row['id'];?>"><?php echo $row['name']; ?></option>
<?php
}
?>
</select>
So, for instance, the user clicks "add". An identical form element to the one above is created dynamically. I want to be able to increase the name of the form element by one, each time a user clicks the "add" button. So, if the first select element's name is "name", then when the user clicks on the "add" button to add another select element, its name becomes "name-1". If the user clicks on the "add" button again, then the select element's name becomes "name-2".
How would I determine how many elements a user added and how would I echo out all of their values??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're creating a time bomb by using MySQL. Get off it, and choose one of the other data base extensions. This article tells why MySQLis being removed from PHP and what you must do to keep your scripts running in the future.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
greetings Jdizzleextreme, , you ask - "How would I determine how many elements a user added and how would I echo out all of their values??"
As you have described your setup, you can use javascript to add whatever inputs you want to any form, and you can use the JS examples here to add a SELECT to your FORM, , However, these SELECT will always be empty!, you can not use PHP (server side) to populate the Options from a SELECT database retrieve.
You more or less have two options to populate the options,
ONE: to load javascript arrays from PHP SELECT that can populate the Options for ALL user additions made
OR
TWO: to use a javascript AJAX to contact the server and get back the SELECT database retrieve.
AJAX is not so easy, but it is used to good effect on many web sites now.
As you have described your setup, you can use javascript to add whatever inputs you want to any form, and you can use the JS examples here to add a SELECT to your FORM, , However, these SELECT will always be empty!, you can not use PHP (server side) to populate the Options from a SELECT database retrieve.
You more or less have two options to populate the options,
ONE: to load javascript arrays from PHP SELECT that can populate the Options for ALL user additions made
OR
TWO: to use a javascript AJAX to contact the server and get back the SELECT database retrieve.
AJAX is not so easy, but it is used to good effect on many web sites now.
I've requested that this question be deleted for the following reason:
Not enough information to confirm an answer.
Not enough information to confirm an answer.
The answers are here:
https://www.experts-exchange.com/questions/28224592/Create-an-Array-echo-the-results-of-the-array.html?anchorAnswerId=39444678#a39444678
https://www.experts-exchange.com/questions/28224592/Create-an-Array-echo-the-results-of-the-array.html?anchorAnswerId=39444730#a39444730
https://www.experts-exchange.com/questions/28224592/Create-an-Array-echo-the-results-of-the-array.html?anchorAnswerId=39444964#a39444964
https://www.experts-exchange.com/questions/28224592/Create-an-Array-echo-the-results-of-the-array.html?anchorAnswerId=39444678#a39444678
https://www.experts-exchange.com/questions/28224592/Create-an-Array-echo-the-results-of-the-array.html?anchorAnswerId=39444730#a39444730
https://www.experts-exchange.com/questions/28224592/Create-an-Array-echo-the-results-of-the-array.html?anchorAnswerId=39444964#a39444964
No offense meant, but this process is a waste of time if the parties involved do not understand the technologies involved. We are just trying to help other member of EE, and the closing + review + repeat + admin detracts from the experience. A lot.
Open in new window