-2

動作する製品をシミュレートしようとしていて、20 ~ 100 の値 (ページの読み込みごとにランダム) のテーブルに挿入したい情報の PHP 配列を作成しましたか?

したがって、ある意味では、配列はある種の「データベース」として機能し、20 ~ 100 の値のランダム テーブルを生成します。

$facilitiesやなどの特定の配列$roomでは、3 つの異なる値を選択してテーブルに挿入したいと考えています。

どうすればこれを行うことができますか?

ここに私の配列があります:

<?php
// module code array
$moduleCode = array("XXX101","XXX107","XXX122","XXX123","XXX124","XXX201","XXX220","XXX256","ZZZ101","ZZZ106","ZZZ107","ZZZ108","ZZZ120","ZZZ150","ZZZ201","ZZZ231","ZZZ232","ZZZ249","ZZZ251","ZZZ290","ZZZ295","ZZZ301","YYY001","YYY003","YYY101","YYY102","YYY104","YYY104","YYY106","YYY107","YYY131","YYY140","YYY170","YYY180","YYY190","YYY201","YYY202","YYY220","YYY221","YYY251","YYY253","YYY255","YYY257","YYY259","YYY281","YYY800","YYY801","YYY802","NNN280","NNN290");
// random no of students between 20 and 400
$noStudents = rand(20, 400);
// day of the week
$day = array("1 - Mon","2 - Tues","3 - Wed","4 - Thu","5 - Fri");
// period of the day
$period = array("1 - 09:00","2 - 10:00","3 - 11:00","4 - 12:00","5 - 13:00","6 - 14:00","7 - 15:00","8 - 16:00","9 - 17:00");
// length of lecture
$lecture = rand(1, 7);
// weeks
$weeks = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");
// facilities
$facilities = array("Blu-ray DVD Player","Chalk board","Computer","Data projector","Dual data projector","DVD/Video","Glass board","Induction loop","Interactive PC monitor","Loop system","Microphone","OHP","PA","PC & laptop audio","Plasma screen","Radio mic","Review","Twin data projector","Video/DVD","Visualizer","Wheelchair access","White board",
"White/green board");
// room preferences
$room = array("J110","CC011","U020","CC012","CC013","J001","A201","J002","GGB01","A001","J104","B111","U011","A203","K108","D002","D102","D109","D201","D202","G006","G007","CC014","K105","CC109","CC110","U012","K109","U112","CC111","K106","G002","G003","G004","CC113","K107","U013","U014","N326","BE025","SMB014","SMB017","SMB103","SMB104","SMB008","SMB010","SMB102","SMB105","SMB109","SMB108","Cope","HE010","JB021","XX019","JJ004","ZZ106","HE023","HE021","HE026","63.1.07","JJ018","NN006","ZZ105","ZZ103","63.1.08","JJ017","XX031","XX031a","T003","RT037","W001","S004","W004","RT033","RT040","W003","S174","S173","W002","RT027","X401","W005A","W005B","W005C","S177","W005D","W005E","W005F","S006","T210","KG107","KG109","KG111","KG112");
?>
4

1 に答える 1

1

テーブルを作成し、ループを使用して行にデータを入力できます。array_rand()を使用して、ランダム キーを生成できます。

さらに追加するだけで、<td>必要なすべてのフィールドを取得できます。

<table>
<?php
for($i=0; $i<10;++$i){
echo '<tr>';
echo '<td>' . array_rand($moduleCode) .'</td>;
echo '</tr>';
}
?>
</table>
于 2012-11-05T06:06:08.633 に答える