doomy Posted May 25, 2014 Share Posted May 25, 2014 (edited) for starters, i am a complete beginner at PHP, so i know almost nothing. so, the basic outline is that i am required to create a table with 2 columns, and use PHP where i can so the first set of code lays down the table and the ability to type in text of "name" and "surname". ----i think this "input" is HTML, yes?? is there a way to enter it as PHP? <table border=\"2\"> <tr><th><b>Requirements</b></th><th><b>Selections</b></th></tr> <tr><td>Name</td><td><input type="text" name="name"/></td></tr> <tr><td>Surname</td><td><input type="text" name="surname"/></td></tr> so, for this next section, adding on is the part for "age". i want this to appear as a dropdown selection. i've written PHP where possible, however this does not work when opening the file in a browser. it simply leaves a blank dropdown menu with no options. ???? <tr><td>Age</td><td><select> <?php for ($num=11; $num<=22; $num++){ echo '<option>' .$num. '</option>'; } ?> </select> lastly, i have the part for "activity choice". this again i believe i wrote the radio buttons in HTML??? am i able to write this as PHP???? <tr><td>Activity Choice</td><td><input type="radio" name="activityChoice" value "music"/> Music ($30.00)<br> <input type="radio" name="activityChoice" value "swimming"/> Swimming ($25.50)<br> <input type="radio" name="activityChoice" value "tennis"/> Tennis ($20.00)<br> <input type="radio" name="activityChoice" value "basketball"/> Basketball ($15.50)<br> <input type="radio" name="activityChoice" value "netball"/> Netball ($15.50)<br> <input type="radio" name="activityChoice" value "dance"/> Dance ($10.50)<br> <input type="radio" name="activityChoice" value "communityService"/> Community Service (No Charge)</td></tr> please please please help?? Edited May 25, 2014 by doomy Quote Link to comment https://forums.phpfreaks.com/topic/288755-putting-for-loops-into-dropdowns-and-arrays-into-radio-buttons-in-a-html-table/ Share on other sites More sharing options...
Ch0cu3r Posted May 25, 2014 Share Posted May 25, 2014 i think this "input" is HTML, yes?? is there a way to enter it as PHP? No, HTML is used for creating the inputs. PHP is used for retrieving the data entered into the form fields when the form has been submitted. You can also use PHP to generate the HTML for the input fields, example $fields = array('firstname', 'surname'); foreach($fields as $field) { echo ucwords($field) . ': <input type="text" name="'.$field.'" /><br />'; // generate a text input field for current item } i want this to appear as a dropdown selection. i've written PHP where possible, however this does not work when opening the file in a browser. it simply leaves a blank dropdown menu with no options. ???? The code you posted is correct. You are most likely entered the PHP code in a .html file. Most servers are not configured to interpret .html files as PHP code. You should save your file with a .php file extension. Or you are directly opening your .php file directly in the browser. PHP is a server side language, HTML is a client side language. Web browsers only know how to parse client side languages. PHP on the other hand needs be parsed by the http server, which is why it requires a server environment. If you are new to PHP you can install a package such as wamp or xampp which will allow you to run your PHP code locally on your computer. Otherwise you will need to upload all your sites files to a webhost and you test your code that way. lastly, i have the part for "activity choice". this again i believe i wrote the radio buttons in HTML??? am i able to write this as PHP???? You could generate the radio buttons using PHP, similar to my example code I posted above. Quote Link to comment https://forums.phpfreaks.com/topic/288755-putting-for-loops-into-dropdowns-and-arrays-into-radio-buttons-in-a-html-table/#findComment-1480776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.