亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何匯總 html 表中的總行數 - 在 phpmyadmin 中綁定

如何匯總 html 表中的總行數 - 在 phpmyadmin 中綁定

PHP
忽然笑 2022-06-17 17:01:28
我在 html 中有一個表格。正在使用 php 從 phpmyadmin 獲取數據。我想合計每一行中的值。請幫忙。<?php// Connect to the database$dbLink = new mysqli('localhost', 'root', '', 'ghsexam_database');if(mysqli_connect_errno()) {die("MySQL connection failed: ". mysqli_connect_error());}// Query for a list of all existing files$sql = 'SELECT `last_name`, `first_name`, `middle_initial`, `educ_attain`, `logic1`, `logic2`,`logic3`,  `grammar1`, `grammar2`, `grammar3`, `grammar4`, `grammar5`, `ghs_essay`, `reading1`, `reading2`, `reading3`, `reading4`, `listening1`, `listening2` FROM `ghs_table` ';$result = $dbLink->query($sql);// Check if it was successfullif($result) {// Make sure there are some files in thereif($result->num_rows == 0) {    echo '<p>There are no files in the database</p>';}else {    // Print the top of a table    echo '<center><table id=myTable table border=4 cellspacing=1 cellpadding=1 width="100%">            <tr class="header">                <th onclick="sortTable(0)" style="cursor:pointer; "nowrap="nowrap"><b>Last Name</b> <i class="fa fa-fw fa-sort"></i></th>                <th onclick="sortTable(1)" style="cursor:pointer;" nowrap="nowrap"><b>First Name</b> <i class="fa fa-fw fa-sort"></i></th>                <th onclick="sortTable(2)" style="cursor:pointer;" nowrap="nowrap"><b>Middle Initial</b><i class="fa fa-fw fa-sort"></i></th>                <th onclick="sortTable(3)" style="cursor:pointer;" nowrap="nowrap"><b>Educational Attainment</b><i class="fa fa-fw fa-sort"></i></th>                <th onclick="sortTable(4)" style="cursor:pointer;" nowrap="nowrap"><b>Logic:1:</b><i class="fa fa-fw fa-sort"></i></th>      </tr>';我在這部分有問題。我想合計每一行的有限值。喜歡,1 1 1 1 1 = 5。在下面免費填寫評論。
查看完整描述

2 回答

?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

您應該使用以下方式更新您的代碼:


<script language='javascript' type='text/javascript'>

  var sum = 0;

  $('td').each(function(){

    var tdTxt = $(this).text();

      if($(this).hasClass('count-me')) {

        $(this).text(sum);

        sum = 0;

      } else {

        sum+= parseFloat(tdTxt);    

      } 

  });

  document.getElementById('myTable').innerHTML += '<td>as<td>' + sum + '</td>';

    </script>


查看完整回答
反對 回復 2022-06-17
?
茅侃侃

TA貢獻1842條經驗 獲得超22個贊

我不確定我是否理解正確。你想總結每一行的列嗎?像邏輯1+邏輯2+邏輯3?如果這是你想要的嘗試這樣的事情:


$sql = '

SELECT 

    `last_name`,

    `first_name`,

    `middle_initial`,

    `educ_attain`,

    `logic1`,

    `logic2`,

    `logic3`,

    (`logic1`+`logic2`+`logic3`) AS logic_sum,

FROM

    `ghs_table`

';

在 logic_sum 中,您將匯總所有邏輯列。當然,在語法、閱讀和聽力中重復一遍。希望能幫助到你。


查看完整回答
反對 回復 2022-06-17
  • 2 回答
  • 0 關注
  • 117 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號