I was wondering if this is safe or not. By that, I mean I send it different length information.
For example, I may send it
SELECT year FROM table
one time then the next time send
SELECT id, product FROM table
In the first one, it only gathers one column, so I make ( $row[1] ) equal to the column sent ( $row[0] ).
The second one has an ID already. It works, but I am unsure if I may have troubles with it down the road.
function dropdown( $name, $options, $selected )
{
$dropdown = "<td> ".$name.": \
";
$dropdown .= "<select name=\\"".$name."\\">\
";
while ($row = mysql_fetch_array($options)) {
$select = $selected==$row[0] ? ' selected' : null;
if (!isset($row[1])){ $row[1]=$row[0]; }
$dropdown .= "<option value=".$row[0]." ".$select.">".$row[1]."</option>\
";
}
$dropdown .= "</select></td>\
";
return $dropdown;
}
I guess another question would be is me sending a resource as $options bad or is there another way?
$week = 1;
$query = "SELECT DISTINCT " .
"week " .
"FROM {{table}} " .
"ORDER BY week ASC";
$result = doquery($query, "games");
$page .= dropdown( 'week', $result, $week );