나는 모든 자원 봉사자들을 저장하는 테이블을 가지고 있으며, 각 자원 봉사자는 적절한 장소에 배정되어 그 일을한다. 모든 장소를 저장하는 테이블이 있습니다.쿼리에 가입하고 데이터를 올바르게 표시하려면 어떻게해야합니까?
자원 봉사자의 적절한 장소 할당을 venue_id
열에 저장합니다.
table: venues
columns: id, venue_name
table: volunteers_2009
columns: id, lname, fname, etc.., venue_id
여기는 자원 봉사자 목록을 표시하는 기능입니다. 문제는 내가 배정 된 배정을 표시하는 것입니다. 필자가 필요로하는 적절한 정보를 얻기 위해 두 테이블을 결합한 것은 이번이 처음이기 때문에 MySQL 조인으로 많은 일을 해본 적이 없다.
그래서 나는 그것이는 volunteers_2009 테이블로 이동 venue_id을 잡아, 경기장 테이블에 가고 싶어는 자원 봉사의 장소 할당을 표시 목록에 있으므로,venues.venue_name
을 표시,
volunteers_2009.venue_id to venues.id
일치.
alt text http://i35.tinypic.com/16a1cgw.jpg
<?php
// -----------------------------------------------------
//it displays appropriate columns based on what table you are viewing
function displayTable($table, $order, $sort) {
$query = "select * from $table ORDER by $order $sort";
$result = mysql_query($query);
// volunteer's venue query
$query_venues = "SELECT volunteers_2009.venue_id, venues.venue_name FROM volunteers_2009 JOIN venues ON volunteers_2009.venue_id = venues.id";
$result_venues = mysql_query($query_venues);
if($_POST) { ?>
<table id="box-table-a">
<tr>
<th>Name</th>
<?php if($table == 'maillist') { ?>
<th>Email</th>
<?php } ?>
<?php if($table == 'volunteers_2008' || $table == 'volunteers_2009') { ?>
<th>Comments</th>
<?php } ?>
<?php if($table == 'volunteers_2009') { ?>
<th>Interests</th>
<th>Venue</th>
<?php } ?>
<th>Edit</th>
</tr>
<tr>
<?php
while($row = mysql_fetch_array($result))
{
$i = 0;
while($i <=0)
{
print '<td>'.$row['fname'].' '.$row['lname'].'</td>';
if($table == 'maillist') {
print '<td><a href="mailto:'.strtolower($row['email']).'">'.strtolower($row['email']).'</a></td>';
}
if($table == 'volunteers_2008' || $table == 'volunteers_2009') {
print '<td><small>'.substr($row['comments'], 0, 32).'</small></td>';
}
if($table == 'volunteers_2009') {
print '<td><small>1) '.$row['choice1'].'<br>2) '.$row['choice2'].'<br>3) '.$row['choice3'].'</small></td>'; ?>
<td> <?php
if($row_venues['venue_name'] != '') {
// print venue assigned
print $row_venues['venue_id'].' '.$row_venues['venue_name'].' ';
} else { print 'No Venue Assigned'; } ?>
</td> <?php
} ?>
<td><a href="?mode=upd&id=<?= $row[id] ?>&table=<?= $table ?>">Upd</a>/<a href="?mode=del&id=<?= $row[id] ?>&table=<?= $table ?>" onclick="return confirm('Are you sure you want to delete?')">Del</a></td> <?php
$i++;
}
print '</tr>';
}
print '</table>';
}
}
// -----------------------------------------------------
?>
너비가 약 630px 이상인 이미지를 사용하면 랩톱 크기의 해상도를 사용하는 사람들의 서식이 엉망이됩니다. 따라서 너비를 630 픽셀로 설정하려면 img 링크를 편집하는 것이 좋습니다. 감사! –