php - Displaying only 1 column in last row -
i've checked queries in myphpadmin lot of times , dead sure absolutely correct. also, if manually write loop 3 times, setting 2,3,4 instead of incrementing counter still displays 1 column in lastly row. first 2 rows result accurate. foreach($row $rec) running 17 times query printing table headers.
$by_type1 = array("first","second+","final"); $counter = 2; //this counter represents type of interview (2-first, 3-second+, 4-final) foreach ($by_type1 $type1) { $table_row = '<tr><td class="rborder">'.$type1.'</td>'; foreach ($row $rec) { $id=$rec['id']; $qry2 = "select concat( r.fname, ' ', r.lname ) rname, ch.status_id type, count(ch.status_id) number candidatejoborderhistory ch left bring together candidates_info c on ch.candidate_id = c.candidate_id left bring together recruiters r on c.recruiter_id=r.recruiter_id left bring together interviewtypes on ch.interview_id = i.interview_id c.recruiter_id = $id , unix_timestamp(ch.date_interview) between 1401667200 , 1402099200 , ch.status_id = $counter grouping ch.status_id"; global $conn; $conn->open(); $stmt2 = $conn->prepare($qry2); $stmt2->execute(); $row2 = $stmt2->fetchall(); foreach($row2 $row_x) { $table_row .= '<td>'.$row_x['number'].'</td>'; } } $table_row .='</tr>'; echo $table_row . "\n"; $counter++; }
what want is
first 6 6 4 4 11 6 12 3 second+ 3 1 2 1 3 final 3 2 1 4 1
but getting is
first 6 6 4 4 11 6 12 3 second+ 3 1 2 1 3 final 3
let me know if you've problem understanding code flow.
well think mysql approach, i've made changes code , explained them:
$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 $counter=>$type1) { $table_row = '<tr><td class="rborder">'.$type1.'</td>'; foreach ($row $rec) { $id=$rec['id']; $qry2 = "select concat( r.fname, ' ', r.lname ) rname, ch.status_id type, count(ch.status_id) number candidatejoborderhistory ch left bring together candidates_info c on ch.candidate_id = c.candidate_id left bring together recruiters r on c.recruiter_id=r.recruiter_id left bring together interviewtypes on ch.interview_id = i.interview_id c.recruiter_id = $id , unix_timestamp(ch.date_interview) between 1401667200 , 1402099200 , ch.status_id = $counter grouping ch.status_id"; $res = $conn->prepare($qry2); $res->execute(); // loop 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();
code isn't tested if have uncertainty ask. hope helps!
references:
prepared statements executing statements
php mysql sql
No comments:
Post a Comment