我已经通过PHP创建了一个调查问卷。有十个问题,每个问题都与特定的职业有关。我的代码将每个问题的用户输入与每个职业相匹配。在问卷结束时,结果匹配用户与十个职业的兼容性,给出匹配的百分比。我想要显示前5个结果,但不确定使用什么代码以及在哪里使用它。任何帮助都将不胜感激。代码如下:
<?php
//Footballer
$career2sequence1 = mysql_result(mysql_query("SELECT `q1` FROM `careers` WHERE `careerid` = '2'"), 0);
?>
<?php
$career2result1 = $question1/$career2sequence1;
if ($career2result1>1) {
$career2result1 = $career2sequence1/$question1
?>
<?php
}
?>
<?php
$careername1 = 'Nursing ';
$careername2 = 'Footballer ';
$careername3 = 'Dentist ';
$careername4 = 'Hairdressing ';
$careername5 = 'IT ';
$careername6 = 'Trade ';
$careername7 = 'Doctor ';
$careername8 = 'Teacher ';
$careername9 = 'Sales Assistant ';
$careername10 = 'Cook/Chef ';
?>
<h4>
<?php
$nursing = array("Nursing", $result1, "% ", "$link1");
$footballer = array("Footballer", $result2, "% ", "$link2");
$dentist = array("Dentist", $result3, "% ", "$link3");
$hairdresser = array("Hairdresser", $result4, "% ", "$link4");
$IT = array("IT", $result5, "% ", "$link5");
$Trade = array("Trade", $result6, "% ", "$link6");
$Doctor = array("Doctor", $result7, "% ", "$link7");
$Teacher = array("Teacher", $result8, "% ", "$link8");
$SalesAssistant = array("Sales Assistant", $result9, "% ", "$link9");
$CookChef = array("Cook/Chef", $result10, "% ", "$link10");
$items = array($nursing, $footballer, $dentist, $hairdresser, $IT, $Trade, $Doctor, $Teacher, $SalesAssistant, $CookChef);
foreach ($items as $item) {
$item[1].'<-'.$item[0].'<br>';;
}
function compare($a, $b) {
if ($a[1] == $b[1]) {
return 0;
}
return ($a[1] > $b[1]) ? -1 : 1;
}
usort($items, 'compare');
foreach ($items as $item) {
echo implode(' ',$item).'<br>';
}
?>
发布于 2013-04-22 23:11:10
直接在with LIMIT查询中使用它。
SELECT `q1` FROM `careers` WHERE `careerid` = '2' LIMIT 0,5
https://stackoverflow.com/questions/16158090
复制相似问题