我有一个Table
被称为我有不同的技能Fields
喜欢
skillPer1 SkillPer2 SkillPer3 ..... skillPer8. (skillPer=skillPercentage)
和另一个名为user的表,其中包含userImage等。所以我想将这两个表结合起来用于技能结果以及同一div中的用户配置文件
所以,当用户在Skill
中存储他的%
时,我希望在那8个skillPer字段中显示highest
K
例如,用户已skillPer1
PHP
80%
skillPer2
C++
90%
中存储了highest
,因此我希望显示%
} 90%
来自那些 <?php
$userID=$_REQUEST['userID'];
$sql1= "(SELECT *, @maxVal:= GREATEST(skillPer1,skillPer2,skillPer3,skillPer4,skillPer5,skillPer6,skillPer7,skillPer8) as higherPercentage,
CASE @maxVal
WHEN skillPer1 THEN 'skillPer1'
WHEN skillPer2 THEN 'skillPer2'
WHEN skillPer3 THEN 'skillPer3'
WHEN skillPer4 THEN 'skillPer4'
WHEN skillPer5 THEN 'skillPer5'
WHEN skillPer6 THEN 'skillPer6'
WHEN skillPer7 THEN 'skillPer7'
WHEN skillPer8 THEN 'skillPer8'
END AS max_value_skill_name
FROM `skill`) ";
$res1 = mysql_query($sql1) or die(mysql_error());
while ($row1 = mysql_fetch_assoc($res1)) {
?>
<?php
$userID = intval($_SESSION['userid']);
$sql = "(SELECT * FROM user ORDER BY signup_date DESC)";
$res = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($res))
{
?>
<?php echo '../uploads/'.$row['userImage'];?>
<?php echo '../uploads/'.$row1['skillPercentage'];?>
<?php }} ?>
的表格字段
所以基本上我希望这两个语句两个结合在一起,得到用户配置文件以及他的技能最高%但我不知道如何做到这一点
InvalidArgumentException in FileViewFinder.php line 137:
View [auth.register] not found.
in FileViewFinder.php line 137
at FileViewFinder->findInPaths('auth.register', array('D:\xampp\htdocs\blog\resources\views')) in FileViewFinder.php line 79
at FileViewFinder->find('auth.register') in Factory.php line 165
at Factory->make('auth.register', array(), array()) in helpers.php line 779
at view('auth.register') in RegistersUsers.php line 33
at AuthController->showRegistrationForm() in RegistersUsers.php line 19
at AuthController->getRegister()
答案 0 :(得分:0)
您可以编写如下的SQL查询....
SELECT id, GREATEST(a,b,c,d) as higherPercentage FROM `your_table`;
在上面的示例中,a,b,c和d是列... 希望这会有所帮助...
获取最大价值百分比及其技能栏,请尝试以下...
SELECT *, @maxVal:= GREATEST(a,b,c,d) as higherPercentage,
CASE @maxVal WHEN a THEN 'a'
WHEN b THEN 'b'
WHEN c THEN 'c'
WHEN d THEN 'd'
END AS max_value_skill_name
FROM `your_table`
答案 1 :(得分:0)
MySQL
GREATEST()
函数返回给定参数的最大值。
$result = mysqli_query($connection ,"SELECT id, GREATEST(Skill1,Skill2,Skill3,........) as highestskillPercentage FROM table") or die(mysqli_error($connection));
while($row = mysqli_fetch_assoc($result)){
$id = $row['id'];
$percentahe = $row['highestskillPercentage'];
如果您不使用AS highestskillPercentage
,您将获得类似
GREATEST(Skill1,Skill2,skill3,skill4…………………...)
90
48
78
23
85
但如果您使用highestskillPercentage
,则会获得
highestskillPercentage
90
48
78
23
85