PHP inside PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

PHP inside PHP

Post by sirstrumalot »

I'm relatively new, so i'm not sure if this is possible:

I have a select element that has dynamic options pulled on load from the MySQL database. Here's the code:

Code: Select all

<select name="missed_treatClin" class="validate-selection" id="missed_treatClin">
              <option value=" " selected="selected">Please Select</option>
              <?php                                     
                    while($treatClin=mysql_fetch_array($result_user)){
                            $thername = $treatClin[user_fname]." ".$treatClin[user_lname];
                            echo "<option value=\"$thername\">$thername</option>";  
                        }
                    ?>
            </select>
Currently, the prototype validation works, so if they don't select something or the first option is left selected, it asks them to validate. My problem is, once the form is submitted, they can go back to it. In all the other fields, like this one:

Code: Select all

<select name="missed_aptTimeAMPM" id="missed_aptTimeAMPM">
              <option value=" " selected="selected"> </option>
              <option value="AM"<?php if (!(strcmp("AM", $row_missed['missed_aptTimeAMPM']))) {echo "selected=\"selected\"";} ?>>AM</option>
              <option value="PM"<?php if (!(strcmp("PM", $row_missed['missed_aptTimeAMPM']))) {echo "selected=\"selected\"";} ?>>PM</option>
            </select>/>
if the form is viewed again after submitted, all the values fill the document. This allows them to view it and change it and click update.

So my questions is: When I set the select element in the page to dynamic, I seemed to have limited my ability to echo the php value if a particular option is selected, so when they go BACK to the form to update it, they have to select an option every time. I don't know how to echo the selected option inside the already generating PHP. Any suggestions?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP inside PHP

Post by Mark Baker »

Start reading about Ajax
Post Reply