not able to get the data and display on web using php - php

$totDays = cal_days_in_month(CAL_GREGORIAN,$_REQUEST['month'],$_REQUEST['year']);
$attData = $commonObj->getAttendanceData($_REQUEST['month'],$_REQUEST['year']);
`
Student Name
<?php foreach($attData as $attk=>$attv){
$punchin = $commonObj->getTimeOfDate($attData[$attk]['punchin']);
$punchout = $commonObj->getTimeOfDate($attData[$attk]['punchout']);
$nam=$attv['name'];
?>
<tr>
<th class="danger">
<?php echo $nam;?>
</th>
<?php for($i=1;$i<=$totDays;$i++){?>
<?php if($commonObj->getDayOfDate($attData[$attk]['punch_time']) == $i){
echo "<td class='success' id='att_$i'>".$punchin.'-'.$punchout;?>
<table class="table table-responsive"style="display: none; position:relative;min-width:100px;max-width:200px; margin-top: -40px;" id="<?php echo "det_att_".$i;?>">
<tr>
<td>Time:</td>
<td><?php echo "p"?>
</td></tr>
<tr>
<td>UID:</td>
<td><?php echo $attData[$attk]['rfid_uid'];?></td>
</tr>
</table>
<?php
}else {echo "<td class='info'>#na";}?>
</td>
<?php }?>
</tr>
<?php }?>
</tr>
</table>`
this is the code for displaying on the web for viewing attendance ..
and here is the code for database part for getting attendance...
public function getAttendanceData($month,$year){
if(!is_numeric($month) || $month>12 || $month<1){
$this->setErrorMsg("Please Select valid month!");
header("location:viewAttendance.php");
exit;
}
$retData = array();
$fullDate = $year."-".$month;
//print_r($_SESSION);
if($_SESSION['user_type']==1){
$sql = "
SELECT t1.*
, t2.rfid_uid
, punch_time as punchin
, t2.name
FROM tbl_attendance as t1
right
join tbl_users as t2
on t1.rfid_uid = t2.rfid_uid
WHERE YEAR(punch_time) = $year
AND MONTH(punch_time) = $month
and t2.rfid_uid ='".$_SESSION['rfid_uid']."'
";
$retData = $this->getData($sql);
}else if($_SESSION['user_type'] == 2){
$sql = "SELECT t1.*,t2.rfid_uid,punch_time as punchin,t2.name FROM tbl_attendance as t1 right join tbl_users as t2 on t1.rfid_uid=t2.rfid_uid WHERE YEAR(punch_time) = $year AND MONTH(punch_time) = $month group by t2.rfid_uid";
$retData = $this->getData($sql);
}
return $retData;
}
web viewing imagedatabase table for attendanceuser
the attendance is recorded in the database but is not shown on the web..please help

Related

php/mysql basic search not returing results

I have a test query I am performing and it seems to be running OK, however not returning any data within the rows of the tables when using a varible passed or a direct set year for the table
<?
$curyr = date("Y");
isset($_GET['year']) ? $year = $_GET['year'] : $year = "";
$server = $_SERVER['PHP_SELF'];
$dbhost = "localhost";
$dbuname = "";
$dbpass = "";
$dbname = "";
$conn = new mysqli($dbhost,$dbuname,$dbpass,$dbname);
if($conn->connect_errno):
die("$conn->connect_error \n");
endif;
echo ("<title>$year</title>");
if (($year >= 2001) && ($year <=$curyr)) {
echo ("
<table border='0' align='center' width='100%'>
<tr>
<td>
<table border='1' align='center' width='60%' style='border:1 solid #000000; border-collapse: collapse'>
<tr>
<th align='center' colspan='5'>
DETAIL
</th>
</tr>");
$query = "SELECT c.* , p.* FROM $year c, dataset p WHERE c.id = p.id ORDER BY p.name ASC";
$r = $conn->query($query);
while ($row = $r->fetch_assoc()) {
echo ("
<tr>
<td>
$row[namepre]$row[name]
</td>
<td>
</td>
<td>
TEST
</td>
<td>
</td>
</tr>");
}
echo ("
</table>
</td>
</tr>
</table>");
} else {
echo ("ERROR NO ROWS");
}
$conn->close();
?>
I'm returning the "detail" portion of the top of the sample table but nothing else. This is just basic but wondering where I'm possibly missing something.

how to fetch colums data from two table using mysql with php using where

I have two Table ownership_profile and socity_unit.
Query For table1: select * from ownership_profile where SID='$id'
Query For Table2: select * from socity_unit where socity_id='$sid'
I have to join with one query, but i don't have idea how to do it.
This is my Php code but gives error:
<!-----------------Table For User Names-------------------------------------->
<table border="1" align="center">
<tr>
<th>Unit No</th>
<th>Member Name</th>
<th>Wing</th>
<th>Unit</th>
</tr>
<?php
if(isset($_GET['submit']))
{
$sql = "select * from ownership_profile o inner join society_unit s on o.sid = s.society_id where o.sid = '$sid' ";
$result = mysql_query($sql);
$i=1;
while($row=mysql_fetch_array($result)){
?>
<?php
$name = $row['NAME'];
$unitid = $row['UNIT_ID'];
$sid = $row['SID'];
$wings = $row['wings'];
$unit_no = $row['unit_no'];
{
?>
<!--User Submit Result-->
<tr>
<td><?php echo $unitid; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $wings; ?></td>
<td><?php echo $unit_no; ?></td>
</tr>
<?php }?>
<?php
//echo "<br>";
$i++;
}
}
?>
inner join is what you want.
select *
from ownership_profile o
inner join society_unit s
on o.sid = s.society_id
where o.sid = '$sid'
This assumes that 'sid' and 'society_id' are the relationship identifiers.
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
select * from ownership_profile o inner join socity_unit s on o.SID = s.socity_id where o.SID = '$SOCIETY_ID'
This query working fine but...... its generate dublicate entry from table

dynamically generate HTML table from MySQL

I have three mysql tables subjects, examinations, examinfo
TABLE - SUBJECTS
subjectid
subjectname
subjectExamid
TABLE - EXAMINFO
examid
exam
TABLE EXAMINATIONS
fname
lname
studentid
score
subjectid
ON subject.subjectExamid = exam.examid
ON examination.subjectid = subject.subjectid
Now i would like to generate HTML table indicating scores students get per paper against subject
STRUCTURE TABLE OUTPUT
Student details against each subject score
EDIT CODE SAMPLE
<?php
$examinid = 3;
$subjects = mysqli_query(
$con,"
SELECT * FROM subjects
WHERE examid = '$examinid'
ORDER BY shortname ASC
");
$content = mysqli_query(
$con,"
SELECT DISTINCT exam.idcandidate, exam.sex, exam.fname, exam.lname
FROM examinations
AS exam
INNER JOIN examinfo
AS info
ON exam.id_subject = info.idsubject
WHERE info.idexam = '$examinid'
");
?>
<div id="table_1">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="table1tr">#</td>
<td class="table1tr">Candidate</td>
<td class="table1tr">ID</td>
<td class="table1tr">Sex</td>
<?php
// output subjects
while($subRow = mysqli_fetch_array($subjects)){
$arbv = strtoupper($subRow['shortname']);
$subjectname = ucwords(strtolower($subRow['subjectname']." - ".$subRow['subjectid'].""));
?>
<td class="table1tr" title="<?php echo $subjectname; ?>">
<?php echo $arbv; ?>
</td>
<?php
}
?>
<td class="table1tr">Exam</td>
</tr>
<?php
while($stdnt = mysqli_fetch_array($content)){
$fullname = ucwords(strtolower("$stdnt[lname] $stdnt[fname]"));
$studentid = str_replace(array('/', 'M', 'W', 'S', 'F', '-'), "",$stdnt['idcandidate']);
if($sex = $stdnt['sex'] == Male){
$sex = M;
}else{ $sex = F; }
$id_subject = $stdnt['id_subject'];
$x++;
$zebra_1 = ($x%2)? 'TableZebra_1': 'TableZebra_2';
?>
<tr>
<td class="<?Php echo $zebra_1; ?>"><?php echo $count++; ?></td>
<td class="<?Php echo $zebra_1; ?>"><?Php echo $fullname; ?></td>
<td class="<?Php echo $zebra_1; ?>"><?php echo $studentid; ?></td>
<td class="<?Php echo $zebra_1; ?>"><?php echo $sex; ?></td>
<td class="<?Php echo $zebra_1; ?>">
<!-- Problem is here how to output the subject grades $grade -->
<!--
My first unsuccessful approach
SELECT score
FROM examinations AS test
INNER JOIN examinfo AS testinfo ON testinfo.idsubject = test.id_subject
WHERE testinfo.idexam
IN (
SELECT idexam
FROM examinfo
WHERE idexam = $examinid
)
AND test.id_subject = $id_subject AND test.idcandidate = '$studentid'
Then output results - But this falls it shows one student subjects in one cell
-->
</td>
<td class="<?Php echo $zebra_1; ?>">Exam</td>
</tr>
<?php
} // loop content
?>
</table>
</div>
If your solution is not concat(); you may first
follow the simple steps
1 loop $contents // to get info such as studentid
2 inside the loop of $contents loop $subjects // to get all subjects including subjectids
3 inside $subject loop, loop examinations table where studentid = '$studentid' AND subjectid = '$subjectid'
if step three return null echo empty cell otherwise echo cell with score
I have no time to test this, but you may follow the steps and it will work otherwise try google search

add list selector to mysql query

I have a php scrip that runs a MySQL query and returns some data. What I am wanting to do is control the returned results with a dropdown.
The dropdown would need to have the following info inside it for the student to select from.
SELECT courseid FROM course_students WHERE userid = $user
Below is the current code that I have..... I am trying to figure out how to incorporate the above with it:
<?php
defined('_JEXEC') or die;
$db = JFactory::getDBO();
$user = & JFactory::getUser();
$userid = $user->get('id');
$course = "SELECT
c.coursename
FROM
courses AS `c`
LEFT OUTER JOIN course_students AS s
ON s.courseid = c.id
WHERE s.userid = '1285'";
$courses= mysql_fetch_array($course);
?>
Please Select Course for Results:
<select>
<?php foreach($courses as $c){
echo "<option value='$c'>".$c."</option>";
} ?>
</select>
<?php
$sql =
"SELECT
as.name,
DATE_FORMAT(s.starttime, '%b %d, %Y %H:%i') AS TIME,
s.totalhours AS hrs
FROM
clinicalsites AS `as`
LEFT OUTER JOIN clinical_dashboard AS s
ON s.clinicalsite = as.id
WHERE s.userid = $userid
AND starttime > NOW()
AND courseid = $c";
$db->setQuery($sql);
$rows = $db->loadObjectList();
?>
<style>
table, td, th
{
border-bottom:1px solid black;
text-align:center;
}
th {
background-color:#000000;
color: #FFF;
}
.upcoming {
font-weight: bold;
}
.complete {
font-weight: bold;
color: #060;
}
.pending {
font-weight: bold;
color: #F00;
}
.approved {
color: #C60;
}
</style>
<table width="396">
<tr>
<th width="162">Type of Hours</th>
<th width="70">Pending</th>
<th width="74">Approved</th>
<th width="70">Complete</th>
</tr>
</table>
<table>
<tr>
<td width="162">Total Hospital Hours</td>
<td class="pending" width="70"><?php
$q2 = "SELECT
SUM(totalhours) AS sum2
FROM
clinical_dashboard
WHERE userid = $userid
AND clinicaltype = 'Hospital'
AND instructorapproval = '1'
AND courseid = $c";
$result2 = mysql_query($q2);
$row2 = mysql_fetch_assoc($result2);
echo $row2['sum2']
?></td>
<td class="approved" width="74">
<?php
$q3 = "SELECT
SUM(totalhours) AS sum3
FROM
clinical_dashboard
WHERE userid = $userid
AND clinicaltype = 'Hospital'
AND instructorapproval = '2'
AND courseid = $c";
$result = mysql_query($q);
$row3 = mysql_fetch_assoc($result);
echo $row3['sum2']
?>
</td>
<td class="complete" width="70">
<?php
$q4 = "SELECT
SUM(totalhours) AS sum4
FROM
clinical_dashboard
WHERE userid = $userid
AND clinicaltype = 'Hospital'
AND instructorapproval = '2'
AND STATUS = '2'
AND courseid = $c";
$result = mysql_query($q4);
$row4 = mysql_fetch_assoc($result);
echo $row4['sum4']
?>
</td>
</tr>
<tr>
<td>Total Pre-Hosptial Hours</td>
<td class="pending" ><?php
$q = "SELECT
SUM(totalhours) AS sum3
FROM
clinical_dashboard
WHERE userid = $userid
AND clinicaltype = 'Pre-Hospital'
AND instructorapproval = '1'
AND courseid = $c";
;
$result = mysql_query($q);
$row1 = mysql_fetch_assoc($result);
echo $row1['sum3']
?></td>
<td class="approved">
<?php
$q = "SELECT
SUM(totalhours) AS sum3
FROM
clinical_dashboard
WHERE userid = $userid
AND clinicaltype = 'Pre-Hospital'
AND instructorapproval = '2'
AND courseid = $c";
$result = mysql_query($q);
$row1 = mysql_fetch_assoc($result);
echo $row1['sum3']
?></td>
<td class="complete"><?php
$q = "SELECT
SUM(totalhours) AS sum3
FROM
clinical_dashboard
WHERE userid = $userid
AND clinicaltype = 'Pre-Hospital'
AND instructorapproval = '2'
AND STATUS = '2'
AND courseid = $c";
$result = mysql_query($q);
$row1 = mysql_fetch_assoc($result);
echo $row1['sum3']
?></td>
</tr>
<?PHP foreach ($rows as $row): ?>
<?php endforeach ?>
</table>
<p class="upcoming">Upcoming Clinical Schedule</p>
<table width="393" border="1">
<tr>
<th width="166">Clinical Site</th>
<th width="119">Date</th>
<th width="86">Total Hours</th>
</tr>
</table>
<table>
<?PHP foreach ($rows as $row): ?>
<tr>
<td width="170"><?php echo $row->name ?></td>
<td width="124"><?php echo $row->time ?></td>
<td width="84"><?php echo $row->hrs ?></td>
</tr>
<?php endforeach ?>
</table>
<p class="upcoming"></p>
Below is just the drop down queries with the select.
$course = "SELECT
c.coursename
FROM
courses AS `c`
LEFT OUTER JOIN course_students AS s
ON s.courseid = c.id
WHERE s.userid = '1285'";
$courses= mysql_fetch_array($course);
?>
Please Select Course for Results:
<select>
<?php foreach($courses as $c){
echo "<option value='$c'>".$c."</option>";
} ?>
</select>
I believe you need something like this
<select>
<? foreach($courses as $c){
echo "<option value=".$c['table_id'].">".$c['coursename']."</option>";
} ?>
</select>
Good Luck !
Also select the table id in the query, in order to use it as the value for "option"

grouping class names together in my CMS php

I am done with a CMS school system which i created from scratch for practice in php. My question is for example I have Accounting 101, Computer Science 101, however there must multiple times for Accounting 101. For example: Ticket 1035, 1036 are both Accounting 101 and they should appear in the same table, but in my code it shows them in different classes. Here is my code.
if(isset($_GET['id']))
{
$category = $_GET['id'];
$sql = "SELECT * FROM classes WHERE category_id = " . $category;
$query2 = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_object($query2))
{
?>
<center><h3><?php echo $row->class_name . '-' . $row->units; ?> </h3></center>
<table border ="0" wdith="100%">
<tr>
<td>
<strong>Description: </strong>
<?php echo $row->class_description; ?>
</tr>
</td>
</table>
<br/>
<table border="1" width="44%">
<tr>
<td width="60"><b>Ticket</b> </td>
<td width="123"><b>Days</b></td>
<td width="120"><b>Hours</b></td>
<td width="64"><b>Room</b></td>
<td><b>Instructor</b></td>
</tr>
<tr>
<td width="60"> <?php echo $row->ticket; ?> </td>
<td width="123"><?php echo $row->days; ?></td>
<td width="120"><?php echo $row->start_hours . $row->time_format . '-' . $row->end_hours . $row->time_format2 ; ?> </td>
<td width="64"> <?php echo $row->room_number; ?></td>
<td><?php echo $row->instructor_name; ?></td>
</tr>
}//end while
}//end if
Its showing Accounting 101 with different tickets in different tables, but it should be all in 1 table. Thanks.
You need a double loop if you're trying to get records inside of records. For example:
while ($row1 = mysql_fetch_object($query1))
{
echo $row1->ParentName;
$query2 = 'select * from `mytable` where `myForeignKey` = ' . $row1->ParentId;
while ($row2 = mysql_fetch_object($query2))
{
echo $row2->ChildName;
}
}
You could also do a left join. Let me know if you need a sample of that.
Edit:
The left join would be done like this:
$sql = "select * from `classes` as a where category_id = '{$category}' left join `tickets` as b on a.id = b.class_id"
Ref. http://www.w3schools.com/sql/sql_join_left.asp

Categories