我的代码是在第13行starttimer.php?testid=$row[0]
中,我想在会话testid
中分配$row[0]
的值。帮我做这个。(数据库表为rec_test
,列为pid
)
<?php
extract($_GET);
$rs=mysql_query("select * from rec_test");
if(mysql_num_rows($rs)<1)
{
echo "<br><br><h2 class=head1> No Quiz available </h2>";
exit;
}
echo "<h2 class=head1> Select Quiz Name to Give Quiz </h2>";
echo "<table align=center>";
while($row=mysql_fetch_row($rs))
{
echo "<tr><td align=center ><a href=starttimer.php?testid=$row[0]<h3><font color=red>$row[1]</font></h3></a></td></tr>";
echo "<tr><td> </td></tr>";
}
echo "</table>";
?>
我不知道我是否完全理解你的问题,但我猜你想把pid
列分配给链接。
首先要做的是不要使用通用的' *
',其次使用mysql_fetch_assoc来获得一个关联数组。
<?php
extract($_GET);
$rs = mysql_query("SELECT pid, name FROM rec_test");
if ( mysql_num_rows($rs) < 1 )
{
echo "<br><br><h2 class=head1> No Quiz available </h2>";
exit;
}
echo "<h2 class=head1> Select Quiz Name to Give Quiz </h2>";
echo "<table align=center>";
while ($row = mysql_fetch_assoc($rs))
{
echo '<tr>'
.'<td align="center" >'
.'<a href="starttimer.php?testid='.$row['pid'].'">'
.'<h3><font color="red">'.$row['name'].'</font></h3>'
.'</a>'
.'</td>'
.'</tr>';
echo "<tr><td> </td></tr>";
}
echo "</table>";
也可以考虑切换到Mysqli或PDO,因为mysql扩展名已被废弃并从PHP 5.5开始全部删除。
请不要在不安全的数据上使用extract,正如PHP手册所述:警告
不要在不可信的数据上使用extract(),比如用户输入(即$_GET),带有_file美元,等等)。如果您需要,例如,如果您想运行旧代码它暂时依赖于register_globals,请确保使用其中之一非覆盖标志值,如EXTR_SKIP,请注意您应该按照variables_order中定义的顺序进行提取php.ini.