I am trying to create a page that loops through a set of records and, for one of the cells, create a set of radio buttons (only one can be selected at a time) which are selected/unselected depending on the value in the $active variable (1=active, 0=inactive, 3=pending). My problem is that after the first record (is correctly displayed and selected) none of the subsequent rows have a default selection...they DISPLAY the radio buttons...but the correct items are not SELECTED.... I basically want each row to be evaluated independently, but I guess the radio group name is messing things up..
any ideas?
thank you, in advance, for your help....
Mark
CODE SAMPLE:
<?php
//email text
print("<tr valign=top bgcolor=#C6E7DE>");
print("<td class=header ><form method=POST name=sendemail action=includes/updatelinkinfo.php><input type=hidden name=sendingemail value=1>TO Email Address: <input class=forminput type=text size=20 name=emailtosend value=$emailtosend><br>FROM Email Address: <input class=forminput type=text size=20 name=emailfromsend value=webmaster@houseplangallery.com><br>BCC Email Address: <input class=forminput type=text size=20 name=bcc value=webmaster@houseplangallery.com><br>Subject: <input class=forminput type=text size=20 name=emailsubject value=Reciprocal Link Request></td>");
print("<td class=header colspan=2>Message:<br><textarea NAME=emailmsg COLS=30 ROWS=4>$emailmsg</TEXTAREA></td>");
print("<td class=header colspan=4 valign=bottom><input type=submit name=submitemail value=Submit></form></td>");
print("</font></tr>");
printf("<tr valign=center align=center>");
print("<td class=header>Website Information</td>");
printf("<td class=header>Category</td>");
printf("<td class=header>Submitter</td>");
printf("<td class=header>Websites</td>");
printf("<td class=header>Date</td>");
printf("<td class=header>Current Status</td>");
printf("<td class=header>Update</td>");
printf("</font></tr>");
while ( $row = mysql_fetch_array($result) ) {
$title = ($row['title']);
$url = ($row['url']);
$desc = ($row['desc']);
$submitter = ($row['submitter']);
$phone = ($row['phone']);
$email = ($row['email']);
$active = ($row['active']);
$websites = ($row['websites']);
//get website names
$result_website_names = mysql_query("SELECT * FROM websites where id='$websites'",$db);
$website_name = mysql_result($result_website_names ,0,"website");
$category = ($row['cat']); //this is the lookup id for the link_Cats table
//get categories
$result_category = mysql_query("SELECT * FROM link_cats where id='$category'",$db);
$cat = mysql_result($result_category ,0,"category");
$date_time_submit = ($row['date_time_submit']);
print("<tr valign=top align=left>");
print("<form method=POST name=updatelink action=includes/updatelinkinfo.php>");
print("<td align=left>$title<Br><a href=$url >$url</a><br>$desc</td>");
// put data into drop-down list box
// get categories and build default selection for dropdown
$sql_result = mysql_query("SELECT * FROM link_cats where active = 1", $db);
$num_rows = mysql_num_rows($sql_result);
if ($num_rows < 1){
$option_block = "<OPTION value=\"NoCatSelected\">No Category Selected</OPTION>";
} else {
$option_block = "<OPTION value=\"Select\">Select Category</OPTION>";
};
//get website names
$result_websites = mysql_query("SELECT * FROM websites where active=1",$db);
$num_rows = mysql_num_rows($result_websites);
while ($row = mysql_fetch_array($sql_result)) {
$cat_array = $row["category"];
if ($cat_array = $cat){
$option_block .= "<OPTION selected value=\"$cat_array\">$cat_array</OPTION>";
} else {
$option_block .= "<OPTION value=\"$cat_array\">$cat_array</OPTION>";
};
};
printf("<td><SELECT name=category_select>");
echo "$option_block";
printf("</SELECT></td>");
printf("<td>$submitter<br>$phone<br><a href=mailto:$email>$email</a></td>");
printf("<td class=size9 width=125px >");
while ($row2 = mysql_fetch_array($result_websites)) {
$websitename_array = $row2["website"];
if ($websitename_array == $website_name){
printf("<input type=checkbox CHECKED name=place_on_websites_s value=1> $websitename_array<br> ");
} else {
printf("<input type=checkbox name=place_on_websites_ns value=1> $websitename_array <br> ");
};
};
printf("</td>");
//=======================================
//echo "<td><SELECT name=webname>$option_block</select></td>";
printf("<td>$date_time_submit</td>");
printf("<td>");
//==============================================================
//PROBLEM CODE
//==============================================================
if ($active==1){
print("<input type=radio value=Active checked name=status ><b><font color=blue>ACTIVE</b></font><br>");
print("<input type=radio value=Inactive name=status >Inactive<br>");
print("<input type=radio value=Pending name=status >Pending ");
} elseif ($active==0) {
printf("<input type=radio value=Active name=status ><b>Active</b><br>");
printf("<input type=radio value=Inactive checked name=status ><font color=blue><b>INACTIVE</b></font><br>");
printf("<input type=radio value=Pending name=status >Pending ");
} elseif ($active==3) {
printf("<input type=radio value=Active name=status >Active<br>");
printf("<input type=radio value=Inactive name=status >Inactive<br>");
printf("<input type=radio value=Pending checked name=status ><font color=blue><b>PENDING</b></font> ");
};
//==============================================================
//END PROBLEM CODE
//==============================================================
printf("</td> ");
printf("<td><center><input type=submit name=submit value=Update></td>");
printf("</font></tr>");
};
printf("</table>");
?>
===============================================