我创建了一个PHP表单,其中包含插入数据库中的值。提交后传递给数据库的字段下拉框。根据用户在下拉框中选择的内容,分数会增加。
它包含年龄(下拉框,> 20 <20),学位(高中,大学)等。
我想要构建的是一个根据下拉框选择添加分数值的功能。使特定列值成为添加分数点的变量。
每当有人插入特定选择时,它应获得不同数量的积分。
Pseudocode,得分:
i = 0.
If dropdown.age>20 (choice 1), 5 points, i= i +5.
If dropdown.age<20, 10 points, i= i +10
If dropdownchoicebox.education = high school, 5 points, if university, 10 points.
数据库相同
If age-row.value>20, i +5 else i+10
if education-row.value = highschool, i= i+5 else i + 10
根据每个领域的每个具体选择,它应该继续给予&#34;得分和#34;
到目前为止,代码显示了数据库值。每个插入都在不同的行中,直到它用完行。例如,年龄将是第4行,教育第5行等等。
<?php
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the user profile table.
// Order it by the ordering field.
$query->select($db->quoteName(array(age, education, FieldName, FieldValue)));
$query->from($db->quoteName('table'));
// Reset the query using our newly populated query object.
$db->setQuery($query);
$row = $db->loadRow();
print_r($row);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
?>
结果:数组值
Array ( [0] => over 20 [1] => highschool [2] => result 2[3] => result3
行名:[0] =年龄,[1] =教育。
我想做什么:
Button onclick: calculate points
function calculate points
//i for score
i=0
As 0 = over 20, i=0+5 = 5
as 1 = highschool i= 5+5 = 10