PHP做While循环问题

时间:2017-12-09 05:51:36

标签: php json sql-server

三个查询同时执行,并声明一个对象$ sql。结果“产品”阵列实际上四个记录只显示一个记录,三个记录不显示。在“total”数组中,百分比值显示为null。未在数据库中声明百分比。

我需要这个结果:

 {"success":1,"product":[{"std_Name":"VIVEK SANAPARA","Standard":"12-SCI-CE","Division":"A","ExamDate":{"date":"2016-10-06 00:00:00.000000","timezone_type":3,"timezone":"UTC"},"subject":"MATHS","ExamName":"WT","Marks":"30.00","TotalMarks":"30.00","PassingMarks":"10"},{"std_Name":"VIVEK SANAPARA","Standard":"12-SCI-CE","Division":"A","ExamDate":{"date":"2016-10-07 00:00:00.000000","timezone_type":3,"timezone":"Asia\/Kolkata"},"subject":"PHYSICS","ExamName":"WT","Marks":"15.00","TotalMarks":"30.00","PassingMarks":"10"},{"std_Name":"VIVEK SANAPARA","Standard":"12-SCI-CE","Division":"A","ExamDate":{"date":"2016-10-08 00:00:00.000000","timezone_type":3,"timezone":"Asia\/Kolkata"},"subject":"PHYSICS","ExamName":"WT","Marks":"25.00","TotalMarks":"30.00","PassingMarks":"10"},{"std_Name":"VIVEK SANAPARA","Standard":"12-SCI-CE","Division":"A","ExamDate":{"date":"2016-11-22 00:00:00.000000","timezone_type":3,"timezone":"Asia\/Kolkata"},"subject":"PHYSICS","ExamName":"WT","Marks":"25.00","TotalMarks":"30.00","PassingMarks":"10"},],"total":[{"Marks":"30.00","TotalMarks":"30.00","Percentage":"79.166600"}],"exam":[{"ExamName":"WT"}]}

我在代码下面显示了错误图像。在图像中只有一个记录显示,但在上面的结果中,四个Record.Three Record不在图像中显示。百分比值在图像中显示为空。

Marks.php

if(isset($_REQUEST["insert"])) 
{ 
$reg = $_GET['reg'];

$sql = "select b.std_Name,d.Standard,e.Division,a.ExamDate,f.subject,a.ExamName,a.Marks,a.TotalMarks,a.PassingMarks 
                                  from Marks_mas a  inner join std_reg b on a.regno=b.regno 
                                  INNER JOIN Subject_mas as f ON a.Subject_ID = f.Subject_ID 
                                  inner join StandardMaster d on a.standard = d.STDID 
                                  inner join DivisionMaster e on a.Division = e.DivisionID 
                                  where a.RegNo= '$reg' order by a.ExamDate; select   sum(a.Marks) as Marks,sum(a.TotalMarks) as TotalMarks, sum(a.Marks)/sum(a.TotalMarks) * 100 as Percentage 
                                   from Marks_mas a 
                                   where a.RegNo= '$reg'; select distinct ExamName From Marks_mas;";

$stmt = sqlsrv_query($conn, $sql);

$result = array(); 

 if (!empty($stmt)) {
        // check for empty result
        if (sqlsrv_has_rows($stmt) > 0) {

            $stmt = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);

            $product = array();
            $product["std_Name"] = $stmt["std_Name"];
            $product["Standard"] = $stmt["Standard"];
            $product["Division"] = $stmt["Division"];
            $product["ExamDate"] = $stmt["ExamDate"];
            $product["subject"] = $stmt["subject"];
            $product["ExamName"] = $stmt["ExamName"];
            $product["Marks"] = $stmt["Marks"];
            $product["TotalMarks"] = $stmt["TotalMarks"];
            $product["PassingMarks"] = $stmt["PassingMarks"];

            $total = array();
            $total["Marks"] = $stmt["Marks"];
            $total["TotalMarks"] = $stmt["TotalMarks"];
            $total["Percentage"] = $stmt["Percentage"];

            $exam = array();
            $exam["ExamName"] = $stmt["ExamName"];


            // success
            $result["success"] = 1;

            // user node
            $result["product"] = array();
            $result["total"] = array();
            $result["exam"] = array();


            array_push($result["product"],$product);
            array_push($result["total"],$total);
            array_push($result["exam"],$exam);

            // echoing JSON response
            echo json_encode($result);


        } else {
            // no product found
            $result["success"] = 0;
            $result["message"] = "No product found";

            // echo no users JSON
            echo json_encode($result);

        }

        //sqlsrv_free_stmt($stmt);
        sqlsrv_close($conn); //Close the connnection first  

    }


}

错误在图像中只有一个记录显示及以上实际结果四个记录显示。错误2)百分比值显示为空。

enter image description here

0 个答案:

没有答案