I need all the values of a selected line to appear as radio buttons in a form. Each line has 5 rows, but some lines may have as few as two rows only filled. I don't want any radio buttons to appear when there is no value in the row. Rows 0 has integers. Rows 1 to 4 have string variables. Row 1 is always filled.
At present my code looks like this:
$result = mysql_query("SELECT size,drive1,drive2,drive3,drive4 FROM drivestable WHERE size = $size");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo '<form action="Zip-blackout-drive.php" method="post">';
echo '<div class=nobullets>';
echo '<li>';
echo '<p>'.$row[0].'<p>';
echo'</li><li>';
echo '<p><input type="radio" name="size" value= "' . $row[1] . '">' . $row[1] . '</p>' ;
echo'</li><li>';
if ($row[2]>0) echo '<p><input type="radio" name="size" value= "' . $row[2] . '">' . $row[2] . '</p>' ;
else echo ("");
echo'</li><li>';
if ($row[3]>0) echo '<p><input type="radio" name="size" value= "' . $row[3] . '">' . $row[3] . '</p>' ;
else echo ("");
echo'</li><li>';
if ($row[4]>0) echo '<p><input type="radio" name="size" value= "' . $row[4] . '">' . $row[4] . '</p>' ;
else echo ("");
echo'</li></div></form>';
Without the if else statements, a full set of radio buttons always appears, though no text appears besides them if there is a nul value.
With the if else statements, nothing appears on the screen for the row concerned, even if there is a string variable there.
What should I be using to test for the presence of a string variable?
[Edit As there were only six choices, or no value to cope with, I wrote:
$electric = "Electric";
$hand = "Hand";
$cord = "Cord";
$chain = "Chain";
$hdchain = "HD_Chain";
$gear ="Gear";
$choice = $chain || $hdchain || $electric || $hand || $cord || $gear;
The request for a radio button in, say, row 3 could then be written:
if ($row[3] == $choice) echo '<p><input type="radio" name="size" value= "' . $row[3] . '">' . $row[3] . '</p>' ;
else echo ("");
So my immediate problem is resolved. However, if anyone can tell me how to test for any string value being present, it would help me in the future, I am sure.