View Full Version : Another PHP form problem!!!
Cipher
11-12-2005, 01:52 AM
Now i could build a web form with HTML code and PHP code in same page to send data to MySQL database, now what i want is to make a web form, contains (DropDownList, ListBox) when the user click on item in DropDown, shows him the data for that item in the ListBox from DataBase, also want to use PHP and HTML Form in same page. Thank you alot.
missing-score
11-12-2005, 01:55 AM
So you are wanting to retrieve data from a db and show it in a dropdown box? Do you know how to use MySQL? Take a look at www.php.net/mysql-connect , www.php.net/mysql-query and www.php.net/mysql-fetch-assoc
Cipher
11-12-2005, 03:25 AM
The problem is not in reading from database, i guess you didnt get my question, i have one page called admin, and it contains a DropDownMenu with some subjects, and it has onChange function, when the admin choose a subject, it shows him some controls like text box and a listbox, which i want to view data from MySQL in it.
I know how to view data in list box from database, the question is, how can i get the item that the admin choosed from the DropDownMenu and i'm using PHP Code and the Form in one page.
Cipher
11-12-2005, 03:27 AM
Look i'm sorry, i'm working with asp.net, but i'm stuck with some one which i have to make some thing to him with PHP.
Velox Letum
11-12-2005, 03:36 AM
Erm...the value of the dropdown?
missing-score
11-12-2005, 03:56 AM
Yeah, surely you just set a value in the option and then that gets sent when the form is submit... If you are looking to dynamically load the data when an option is selected then you could pre-load everything or use an XMLHTTP request, but this doesnt (yet) seem like a PHP issue.
If you are looking to retrieve a submitted value, use $_POST or $_GET.
Cipher
11-12-2005, 03:57 AM
//check the subject the user choosed and show specific controls for this subject
if (Topic == "Table1" || Topic == "Table2" || Topic == "Table3" || Topic == "Table4") {
for (i = 0; i < divs.length; i++) {
var obj = document.getElementById(divs[i]);
(divs[i] == "title" || divs[i] == "audio" || divs[i] == "zip")? obj.style.display = "block" : obj.style.display = "none";
}document.getElementById("btn").style.display = "block"
}
Here's the JS onChange function (not the complete function) which triggers when the user select an item, ofcourse when the user logon to page first time, the page will have only the DropDown and DefaultSelect "-----Select Subject", The "Topic" in if statemtn is the table name i need to get data from it, how can i?!
missing-score
11-12-2005, 03:59 AM
So you need to dynamically load the data? Or just pre-load it and have it display on change?
Cipher
11-12-2005, 04:17 AM
i want when the user choose another item from DropMenu to view its data in list pox, depending, dont know if it should depend on the onChange function or no!!
missing-score
11-12-2005, 04:19 AM
Right.... But what do you want to show? Drop menus dont nativley have "data" so what is it you actually want to show?
Velox Letum
11-12-2005, 04:31 AM
Are you asking for a suggestion or what? Your descriptions of your problems are vague, we need more information in order to help you effectively. Contrary to popular belief, we are not psychic, but don't tell our followers that. ;)
Cipher
11-12-2005, 12:14 PM
Well i guess i cant explain a lot, but the pictures wont lie :) ,
now as i you see in the example, all my work is in one page. I have two Menues, DropMenu with Table names, ListBox and its style is set to ("display: none") in the DropMenu when a user select a table, the onChange function will set the ListBox style to ("display: block"), what i want to know, is how can i pass the value of selected table to PHP code.
I have different Values and Text for the Select.
missing-score
11-12-2005, 12:18 PM
Same question again: Do you want to preload the data (eg: have it there when the pages loads, ready to be shown), or do you want to have it dynamic ( data is only loaded on the "onchange" event.
Cipher
11-12-2005, 12:38 PM
Yes on the onChange event.
missing-score
11-12-2005, 12:40 PM
Yes... on the onChange event.... BUT will the data have been preloaded or only get loaded on the onChange?
Cipher
11-12-2005, 12:47 PM
no the data will get loaded, when the user opens the page for first time, there will be no data presents, when the user choose a table, for first time, i want to select the data for first time, after that, when he changes the table from dropmenu, i want to preload the data from the table he chosed.
missing-score
11-12-2005, 12:52 PM
Sorry, i really dont think you know what I'm talking about:
Preloading
When the main page loads (where you select the table from the first dropdown), all the data from all the tables is loaded and put into (for example), a JavaScript array or a hidden select field. When the user changes the main dropdown, it shows the (already-loaded) set of data.
Dynamic XMLHTTP
When the main page loads, no data from tables is loaded. When the users changes the main dropdown, a JavaScript XMLHTTP request is sent, and the returned data can be used to build a second select list.
Please understand, both will have the same visual effect. The second one may take a short time longer to display, however it means you dont have to load everything in the first place.
Which method are you attempting to use?
Cipher
11-12-2005, 01:02 PM
Well i think the first method looks better, but is it gonna work fine if i have alot of data?!
i love asp.net :(
missing-score
11-12-2005, 01:07 PM
This is really absolutley nothing to do with what server side technology you use... its to do with HTML and JavaScript and methods for using them.
You know how to get information from a database in PHP, yes? Do you know enough javascript to show a form field that has been hidden ("display:none;") on the changing of the select box? I mean, this is all you need to do...
What are you having problems with, the loading of the data, the method of storing/displayin it, the SQL query or the JavaScript side of it?
Cipher
11-12-2005, 01:16 PM
well i know how to do both, the problem now is, how can i get the data of selected table after i select all data in page load and put it in any place as you said.
you know in asp.net i dont have to do all of this, all i have to do is to set the <asp:dropdownlist> autopostback attribute event to true, then in the selectedindexchange event i can do all what i want, i know it transforms all to client side scripting, but its not my business :) .
Velox Letum
11-12-2005, 06:52 PM
But if you noticed, this isn't ASP.NET.
http://www.php.net/mysql_query
http://www.php.net/mysql_fetch_assoc
SELECT * FROM table WHERE topic = 'Table1'
Or whatever query you need.
Cipher
11-15-2005, 01:50 AM
Can you show me please how to add data to some place then call it after user choose an item from the dropmenu :rolleyes:.
I know how to read data from MySQL, i know hot create forms controls in php such as ListBoxes, which i need to do, i know how to use javascript, all i need is to select specific data from the table the user chooses from the dropmenu. Thanx alot
missing-score
11-15-2005, 05:17 AM
Can you show me please how to add data to some place then call it after user choose an item from the dropmenu :rolleyes:.
I know how to read data from MySQL, i know hot create forms controls in php such as ListBoxes, which i need to do, i know how to use javascript, all i need is to select specific data from the table the user chooses from the dropmenu. Thanx alot
Sorry.... But i STILL dont get what solution you are after.... Are you sure you know how to write JavaScript? If you know what you say you know, this would be a breeze, and should take about 5 minutes to do... What is making me question your method is that you haven't yet found a solution.
Right, so do you know how to use arrays in JavaScript? Why dont you just load the data into a 3 dimensional array, assign each array an key value and within that, have an array of values to shown when you change the field view... Then create a function to call on the onchange event and dynamicly modify the second box that appears.
Cipher
11-15-2005, 03:19 PM
ok man i did it, thank you alot.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.