我有一个运行 MySQL 查询并返回一些数据的 php 脚本。我想要做的是用下拉菜单控制返回的结果。
下拉列表中需要包含以下信息,供学生选择。
选择 courseid 从 course_students WHERE userid = $user
以下是我拥有的当前代码.....我试图弄清楚如何将上述内容与它结合起来:
<?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>
下面只是带有选择的下拉查询。
$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>