Xtremer360 Posted February 17, 2009 Share Posted February 17, 2009 I found this but I want to know if it's right first. FOREACH array of options AS specific option IF option = value from database THEN set option checked value And if it is can someone explain it more because I'm trying to work it in but don't know how. What I'm asking about is the obviously only select box in this edit form. If say I have one field for active as coming from the titles table and the field called active. So what would the if look like? function editshowname() { $showname = $_GET['showname']; $query = mysql_query("SELECT * FROM `shownames` WHERE `showname` = '" . $showname . "'"); $row = mysql_fetch_array($query); print '<h1 class=backstage>Event Name Management</h1><br />'; print '<h2 class=backstage>Event Name Editor</h1><br />'; print '<form name="editshowname" method="post" action="backstage.php" id="editshowname">'; print '<table width="100%" class="table2">'; print '<tr>'; print '<td width=120 class=rowheading valign=center>Event Name:</td>'; print "<td class=row3><input type=text name=\"showname\" class=fieldtext490 value=\"".$row['showname']."\"></td>"; print '</tr>'; print '<tr>'; print '<td width=120 class=rowheading valign=center>Short Name:</td>'; print "<td class=row3><input type=text name=shortname class=fieldtext140 value=\"".$row['shortname']."\"></td>"; print '</tr>'; print '<tr>'; print '<td width=120 class=rowheading valign=center>Lineup Template:</td>'; print '<td class=row3><select name=lineuptemplate class=dropdown>'; print '</select></td>'; print '</tr>'; print '<tr>'; print '<td width=120 class=rowheading valign=center>Show Template:</td>'; print '<td class=row3><select name=resultstemplate class=dropdown>'; print '</select></td>'; print '</tr>'; print '</table><br />'; print '<input type=checkbox name="deleteshowname"><span class=table1heading>Delete Event Name?</span><br /><br />'; print '<input type="hidden" name="oldshowname" value="'.$row['showname'].'"> '; print '<input type=submit value="Edit Event Name" class=button200 name="editshowname"></form><br />'; print '<input type=submit value="Return to Event Name List" class=button200 name="editshowname"><br /><br />'; print '<h2 class=backstage><input type=submit value="Return to Main Menu" class=button200></form></h2>'; } Quote Link to comment https://forums.phpfreaks.com/topic/145588-solved-for-each-statement/ Share on other sites More sharing options...
RichardRotterdam Posted February 17, 2009 Share Posted February 17, 2009 Uhm ok your description confuses me and the VB code doesn't help. But are you asking for a way to set the selected attribute in a select element? So when the page loads the item was selected is selected in the HTML. Quote Link to comment https://forums.phpfreaks.com/topic/145588-solved-for-each-statement/#findComment-764346 Share on other sites More sharing options...
Xtremer360 Posted February 17, 2009 Author Share Posted February 17, 2009 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/145588-solved-for-each-statement/#findComment-764349 Share on other sites More sharing options...
RichardRotterdam Posted February 17, 2009 Share Posted February 17, 2009 something like this i guess <?php $dbValue="Bob Segat"; $selected=(isset($_POST['submit'])?$selected:$dbValue; $selectItems=array("Bob Segat","Lorenzo Lamas","Chuck Noris","Mr - T"); ?> <select> <?php foreach($selectItems as $item): ?> <option <?php echo($item==$selected)?"selected":"";?> value="<?php echo $item;?>"><?php echo $item;?></option> <?php endforeach; ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/145588-solved-for-each-statement/#findComment-764483 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.