MySQLクエリを実行してデータを返すphpスクリプトがあります。私がやりたいことは、返された結果をドロップダウンで制御することです。
ドロップダウンには、学生が選択できるように、次の情報が含まれている必要があります。
SELECT courseid FROM course_students WHERE ユーザー ID = $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>
以下は、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>