我从mysql数据库中提取数据.我想添加多次运行的长度,并按运行最远的人的等级对它们进行排序.
function determineLength($db, $name){
$getLength = "select length from $db where name = $name and sex = 'male'";
$gettingLength = mysql_query($getLength);
while($gotLenth = mysql_fetch_array($gettingLength)){
more code that calculates total length and returns it as $lengthAccumulator
}
return array('totalLength'=>$lengthAccumulator);
}
Run Code Online (Sandbox Code Playgroud)
现在,我有30个不同的男性,他们的名字永远不会改变,我需要拉动和排序.如何在没有冗余的情况下为每个人运行mysql代码?我只能想出这种方式 -
$name = john;
$a = determineLength($db, $name);
$aLength = $a['totalLength'];
$name = sam;
$b = determineLength($db, $name);
$bLength = $b['totalLength'];
$name = henry;
$c = determineLength($db, $name);
$cLength = $c['totalLength'];
$name = ted;
$d = determineLength($db, $name);
$dLength = …Run Code Online (Sandbox Code Playgroud)