我希望这没有在其他地方被问到,因为我看了,但这里有。我编写了这个函数来为我创建表。它可以工作,但我遇到的问题是每次我调用这个函数时它都会运行查询。有没有办法调用这个函数并将查询传递给函数?
function createawardtables($awardname, $awardshortname, $maxawards, $id){
$query="SELECT * FROM awards WHERE id = $id";
$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error());
while($row = mysql_fetch_array($result)){
$order = array("","1st","2nd","3rd","4th","5th","6th","7th","8th",'9th',"10th");
echo "<table><th colspan=4><font color=maroon size='4pt'><u><b>Orders of the $awardfullname</b></u></font></th>";
for($i=1; $i<$maxawards+1; $i++) {
${$awardshortname.$i} = dateconvert(($row["$awardshortname$i"]), 2);
${$awardshortname.$i.'by'} = $row["$awardshortname{$i}by"];
${$awardshortname.$i.'memo'} = $row["$awardshortname{$i}memo"];
echo "<tr>
<td>$order[$i] Order given on </td>
<td><input type=text name='$awardshortname$i' title='mm/dd/yyyy' value= '${$awardshortname.$i}' size=8/></td>
<td>by <input type=text name='$awardshortname{$i}by' title='Name of who gave the award.' value='${$awardshortname.$i.'by'}'size=15/></td>
<td>for <input type=text name='$awardshortname{$i}memo' title='What the award was give for.' value='${$awardshortname.$i.'memo'}'size=15/></td>
</tr>";
if($i==10 or $awardshortname=="initiate"){
echo "</table><br />";
};
};
};
mysql_free_result($result);
};