Jump to content

Recommended Posts

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>';
}

Link to comment
https://forums.phpfreaks.com/topic/145588-solved-for-each-statement/
Share on other sites

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.

 

 

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.