gpt4 book ai didi

php - 最后一行只显示 1 列

转载 作者:行者123 更新时间:2023-11-29 03:00:33 25 4
gpt4 key购买 nike

我已经在 phpMyAdmin 中检查了很多次查询,并且非常确定它们是绝对正确的。此外,如果我手动编写循环 3 次,设置 2、3、4 而不是递增计数器,它仍然只显示最后一行的一列。前两行结果是准确的。

foreach($row as $rec) 基本上从另一个正在打印表头的查询运行 17 次。

$by_type1 = array("First","Second+","Final"); 
$counter = 2; //this counter represents type of interview (2-First, 3-Second+, 4-Final)

foreach ($by_type1 as $type1)
{
$table_row = '<tr><td class="rborder">'.$type1.'</td>';

foreach ($row as $rec)
{
$id=$rec['id'];
$qry2 = "SELECT
CONCAT( r.fname, ' ', r.lname ) AS rname,
ch.status_id as Type,
count(ch.status_id) as number

FROM candidateJoborderHistory ch

LEFT JOIN candidates_info c ON ch.candidate_id = c.candidate_id
LEFT JOIN recruiters r ON c.recruiter_id=r.recruiter_id
LEFT JOIN interviewtypes i ON ch.interview_id = i.interview_id

WHERE c.recruiter_id = $id AND UNIX_TIMESTAMP(ch.date_interview) BETWEEN 1401667200 AND
1402099200 AND ch.status_id = $counter
group by ch.status_id";

global $conn;
$conn->open();
$stmt2 = $conn->prepare($qry2);
$stmt2->execute();
$row2 = $stmt2->fetchAll();

foreach($row2 as $row_x)
{
$table_row .= '<td>'.$row_x['number'].'</td>';
}
}

$table_row .='</tr>';
echo $table_row . "\n";
$counter++;
}

我想要的是:

First   6   6   4   4   11  6   12  3
Second+ 3 1 2 1 3
Final 3 2 1 4 1

但我得到的是:

First   6   6   4   4   11  6   12  3
Second+ 3 1 2 1 3
Final 3

最佳答案

我认为这是一种 MySQL 方法,我对您的代码进行了一些更改并进行了解释:

$by_type1 = array(2=>"First", 3=>"Second+", 4=>"Final"); 
$counter = 2; //this counter represents type of interview (2-First, 3-Second+, 4-Final)

// Open connection first.
global $conn;
$conn->open();

// Using key => value array gets code simple
foreach ($by_type1 as $counter=>$type1)
{
$table_row = '<tr><td class="rborder">'.$type1.'</td>';

foreach ($row as $rec)
{
$id=$rec['id'];

$qry2 = "SELECT
CONCAT( r.fname, ' ', r.lname ) AS rname,
ch.status_id as Type,
count(ch.status_id) as number

FROM candidateJoborderHistory ch

LEFT JOIN candidates_info c ON ch.candidate_id = c.candidate_id
LEFT JOIN recruiters r ON c.recruiter_id=r.recruiter_id
LEFT JOIN interviewtypes i ON ch.interview_id = i.interview_id

WHERE c.recruiter_id = $id
AND UNIX_TIMESTAMP(ch.date_interview)
BETWEEN 1401667200 AND 1402099200
AND ch.status_id = $counter
GROUP BY ch.status_id";

$res = $conn->prepare($qry2);
$res->execute();

// Loop to get data...
while($row_x = $res->fetch(PDO::FETCH_ASSOC))
{
$table_row .= '<td>'.$row_x['number'].'</td>';
}

}

$table_row .='</tr>';
echo $table_row . "\n";
}
$conn->close();

代码未经测试,但如果您有任何疑问,请尽管提问。希望对您有所帮助!

引用资料:

Prepared Statements Executing Statements

关于php - 最后一行只显示 1 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24434712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com