我为一个作为表格的约会制作了一张表,它显示了一个时段是否空闲,你可以保留它的约会。 这是有效的代码..
$query=mysql_query("SELECT * FROM days ");
echo " <form action=\"change.php\" method=\"post\"><TABLE>";
echo "<TR><Th> Dia <Th> 8 <Th> 9 <Th> 10 <Th> 11<Th>12 <Th> 13 <Th> 14 <Th> 15 <Th> 16 ";
while ($rows=mysql_fetch_array($query)) {
if ($rows['08'] == 'taken') {
$rows['08'] = "<TD id=\"red\" >TAKEN";
}
else {
$rows['08'] = "<TD id=\"blue\" ><input type=\"radio\" name=\"slot\" value= \"08 $rows[day]\" >$rows[08]";
}
if ($rows['09']=='taken') {
$rows['09']="<TD id=\"red\" >TAKEN";
}
else {
$rows['09']="<TD id=\"blue\" ><input type=\"radio\" name=\"slot\" value= \"09 $rows[day]\" >$rows[09]";
}
if ($rows['10']=='taken') {
$rows['10']="<TD id=\"red\" >TAKEN";
}
代码进一步覆盖所有时间段.. 这是一个表格如何看起来的例子..好吧..随着免费单元格旁边有一个无线电按钮:
day 08 09 10 11 12 13 14 15 16
2013-05-05 free free free taken free free taken free free
我要做的是自动化这个。就像在创建一个循环所以我不必重复相同的代码这么多次.. 我尝试了以下但它没有工作:
while ($rows=mysql_fetch_array($query)) {
$c="08";
if ($rows["$c"]=='taken') {
$rows["$c"]='taken';
}
if ($rows["$c"]=='free') {
$rows[$c] = "<input type=\"radio\" name=\"slot\" value= \"$c. $rows[day]\" >$rows[$c]";
}
echo "<TR><TD>$rows[day]"; echo "<TD> $rows[$c]"; $c++;
echo "<TD> $rows[$c]"; $c++;
echo "<TD> $rows[$c]"; $c++;
echo "<TD> $rows[$c]"; $c++;
.....等等..
我认为问题在于将变量放在行数组中 有什么建议?
答案 0 :(得分:1)
$query=mysql_query("SELECT * FROM days ");
echo "<form action='change.php' method='post'><table>";
echo "<tr><td>day</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td></tr>";
while ($rows=mysql_fetch_array($query)) {
while ( $rows=mysql_fetch_assoc($query) ) {
$res[]="<tr><td>".$rows[day];
for ($c="8";$c<="16";$c++)
{
if ($c<10){$ca="0".$c;} else {$ca=$c;}
if ($rows[$ca]=='taken') {
$res[]='taken';
}
if ($rows[$ca]=='free') {
$res[] = "<input type='radio' name='slot' value='".$c." ".$rows[day]." >".$rows[$ca];
}
}
$res[]="</td></tr>";
echo implode("</td><td>",$res);
}
echo "</table></form>";