Click to See Complete Forum and Search --> : [RESOLVED] array in php to combo box in html


shane.carr
06-01-2006, 03:10 PM
Okay, complex question:

Say that there is an html file (test.html) and a php file (test.php). There is an array in test.php (test_array). How do I take test_array from test.php and put it into a combo box in test.html?

nickisme
06-01-2006, 04:47 PM
In really quick terms, I'd advise you to:

-turn the HTML file into a PHP file, so that it can execute bits of PHP
-Find a MySQL database somewhere, create a table in it for your array (eg one that has 2 fields, id and arrayField)
-In the test.php file you referred to, insert this array into this table
-In the old HTML file (which is now a php file, phew), use some php code to select the row of the table that has this array in. Now use a php foreach statement to print the values of the MySQL table in apt places in the combo box

Sorry that's a really fast description, and I'm feeling quite sleepy (so it probably won't make sense), but it's basically what I'd do. If you're not that familiar with MySQL, then I'd strongly advise you to begin checking it out (loads of great tutorials at www.htmlite.com for instance), as I think it's essential for what you're after.

Perhaps someone else has a better way of doing this?

shane.carr
06-01-2006, 05:03 PM
That's a good idea, thanks! But, the html and the php are on dfferent servers. Reason: The main server (the one the html is on) doesn't support PHP. I suppose I could mobe the html to the other server. Another problem is that the array is made dynamically everytime the php is run. I suppose I could copy the function that creates the array to the new file too. If no one else has a simpler way to do it, I'll probably use yours. Thanks again, I appreciate it!

shane.carr
06-03-2006, 04:45 PM
I successfully loaded the php in an <object> tag into the html. However, I now have another problem. View this thread (http://www.webdeveloper.com/forum/showthread.php?p=579009#post579009) for updates. This string is resolved.