Forum Moderators: coopster
I've got a set of radio buttons, and I want to create an IF loop that will execute a function if the value of the radio button is set to the correct value.
The radio buttons can be set to either "Y" or "N", and have variable names (they are called (string)n, where n is an integer relating to an incremented value ($count[FacilityID]).
The closest theory I have is something along the lines of:
IF( $(string)$count[FacilityID] == Y) {statement}
But this creates a parse error (I assume because it uses two $ signs in a single expression.
Does anyone have any idea what I could do?
Let me get this straight. You have a series of radio buttons built from what sounds like a loop.
(some loop mechanism) {
<input type="radio" name=$foo.$count[FacilityID] value="Y">
<input type="radio" name=$foo.$count[FacilityID] value="N">
}
And you want to initiate a function if some condition is true (a certain radio button has been selected).
Just looking at your if statement
IF($(string)$count[FacilityID] == Y) {statement}
Should be written as
IF( $(string).$count[FacilityID] == Y) {statement}
Note the dot (for concantenation) between the count and the string - also note that I used it in building the radio button's name.
I'm afraid I've got a problem still. I believe I've followed your advice, but the script refuses to work.
My radio button area is declared as below:
echo "<table border=0>";
while ($row = mysql_fetch_array($result2)) {
echo "<tr>";
echo "<td>$row[FacilityName]</td>";
echo "<td>Yes <input type=radio name=$foo.$row[FacilityID] value=Y checked></td>";
echo "<td>No <input type=radio name=$foo.$row[FacilityID] value=N></td>";
echo "</tr>\n";
}
echo "</table>";
with $foo declared as (string) elsewhere. The IF statement is declare thus:
while ($count = mysql_fetch_array($result7)) {
if ($(string).$count[FacilityID] == Y){
$sql4 = "INSERT INTO roomfacilities (RoomID, FacilityID) values ($check[RoomID], $count[FacilityID])";
$result4 = mysql_query($sql4);
}
}
But when I try to run it, I encounter this error:
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /disks/diskh/zco/cogeb/public_html/add_room.php on line 26
(line 26 being the line containing the IF statement)
Sorry to bother you again, but can you see the problem?