0

我通过 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>';
}
?>
4

1 回答 1

0

使用 LIMIT 直接在查询中使用它。

SELECT `q1` FROM `careers` WHERE `careerid` = '2' LIMIT 0,5
于 2013-04-22T23:11:09.783 回答