如何在php中设置获取数据的值
我的SQL表中有以下数据:如何在php中设置获取数据的值,php,mysql,Php,Mysql,我的SQL表中有以下数据: id code day time year 1 PRC-001 0 t-1 2017 2 PRC-001 1 t-2 2017 3 PRC-002 0 t-3 2017 4 PRC-002 1 t-4 2017 5 PRC-003 0 t-5 2017 6 PR
id code day time year
1 PRC-001 0 t-1 2017
2 PRC-001 1 t-2 2017
3 PRC-002 0 t-3 2017
4 PRC-002 1 t-4 2017
5 PRC-003 0 t-5 2017
6 PRC-003 1 t-6 2017
输出应如下所示:
Friday Saturday code
09:30-10:30 03:30-04:30 PRC-001
10:40-11:40 04:45-06:00 PRC-002
11:50-12:50 06:10-07:10 PRC-003
如何设置t-1=>09:30-10:30,t-2=>03:30-04:30,第0天=>周五,第1天=>周六的值。我已经为此编写了一个函数。但无法获得价值。这是我的密码:
function getTime(){
$time = array(
t-1 => "09:30 A.M. - 10:30 A.M.",
t-2 => "10:40 A.M. - 11:40 A.M.",
t-3 => "11:50 A.M. - 12:50 P.M.",
t-4 => "03:30 P.M. - 04:30 P.M.",
t-5 => "04:45 P.M. - 06:00 P.M.",
t-6 => "06:10 P.M. - 07:10 P.M.",
);
return $time;
}
function getDay(){
$days = array(
0 => "Friday",
1 => "Saturday",
2 => "Sunday",
3 => "Tuesday",
4 => "Thursday",
);
return $days;
}
$rs = mysql_query("SELECT * FROM routine");
$results = [];
while ($row = mysql_fetch_assoc($rs)) {
$code = $row['code'];
if (!isset($results[$code])) {
$results[$code] = [
'day0' => '-',
'day1' => '-',
];
}
$results[$code]['day' . $row['day']] = $row['time'];
}
?>
<table>
<thead>
<tr id="grey">
<th rowspan="2">Day0</th>
<th rowspan="2">Day1(s)</th>
<th rowspan="2">code</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $code => $result) : ?>
<!--You shouldn't have multiple elements using the same ids-->
<tr>
<td id='clist'><?php echo $result['day0'] ?></td>
<td id='clist'><?php echo $result['day1'] ?></td>
<td id='clist'><?php echo $code ?></td>
</tr>
<?php endforeach ?>
</tbody>
$rs = mysql_query("SELECT * FROM test_work");
$results = [];
$days = [];
while ($row = mysql_fetch_assoc($rs)) {
$code = $row['code'];
if (!isset($results[$code])) {
$results[$code] = [
'day0' => '-',
'day1' => '-',
];
}
$results[$code]['day' . $row['day']] = $row['time'];
$results[$code]['' . $row['time']] = $row['day'];
}
$time = array(
't-1' => "09:30 A.M. - 10:30 A.M.",
't-2' => "10:40 A.M. - 11:40 A.M.",
't-3' => "11:50 A.M. - 12:50 P.M.",
't-4' => "03:30 P.M. - 04:30 P.M.",
't-5' => "04:45 P.M. - 06:00 P.M.",
't-6' => "06:10 P.M. - 07:10 P.M.",
't-7' => "05:30 P.M. - 06:30 P.M.",
't-8' => "06:50 P.M. - 07:50 P.M.",
);
?>
<table>
<thead>
<tr id="grey">
<th rowspan="2">Day0</th>
<th rowspan="2">Day1(s)</th>
<th rowspan="2">code</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $code => $result) : ?>
<!--You shouldn't have multiple elements using the same ids-->
<tr>
<?php $d0 = $result['day0'];
$d1 = $result['day1'];
?>
<td id='clist'><?php echo $time[$d0]; ?></td>
<td id='clist'><?php echo $time[$d1]; ?></td>
<td id='clist'><?php echo $code ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
函数getTime(){
$time=array(
t-1=>“上午9:30-上午10:30”,
t-2=>“上午10:40-11:40”,
t-3=>“上午11:50-下午12:50”,
t-4=>“下午03:30-04:30”,
t-5=>“下午4:45-06:00”,
t-6=>“下午06:10-07:10”,
);
返回$time;
}
函数getDay(){
$days=数组(
0=>“星期五”,
1=>“星期六”,
2=>“星期日”,
3=>“星期二”,
4=>“星期四”,
);
返回$days;
}
$rs=mysql_查询(“从例程中选择*);
$results=[];
while($row=mysql\u fetch\u assoc($rs)){
$code=$row['code'];
如果(!isset($results[$code])){
$results[$code]=[
“day0'=>”-',
“第1天”=>“-”,
];
}
$results[$code]['day.$row['day']]=$row['time'];
}
?>
第0天
第1天(s)
代码
我已经解决了这个问题。这是我的密码:
function getTime(){
$time = array(
t-1 => "09:30 A.M. - 10:30 A.M.",
t-2 => "10:40 A.M. - 11:40 A.M.",
t-3 => "11:50 A.M. - 12:50 P.M.",
t-4 => "03:30 P.M. - 04:30 P.M.",
t-5 => "04:45 P.M. - 06:00 P.M.",
t-6 => "06:10 P.M. - 07:10 P.M.",
);
return $time;
}
function getDay(){
$days = array(
0 => "Friday",
1 => "Saturday",
2 => "Sunday",
3 => "Tuesday",
4 => "Thursday",
);
return $days;
}
$rs = mysql_query("SELECT * FROM routine");
$results = [];
while ($row = mysql_fetch_assoc($rs)) {
$code = $row['code'];
if (!isset($results[$code])) {
$results[$code] = [
'day0' => '-',
'day1' => '-',
];
}
$results[$code]['day' . $row['day']] = $row['time'];
}
?>
<table>
<thead>
<tr id="grey">
<th rowspan="2">Day0</th>
<th rowspan="2">Day1(s)</th>
<th rowspan="2">code</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $code => $result) : ?>
<!--You shouldn't have multiple elements using the same ids-->
<tr>
<td id='clist'><?php echo $result['day0'] ?></td>
<td id='clist'><?php echo $result['day1'] ?></td>
<td id='clist'><?php echo $code ?></td>
</tr>
<?php endforeach ?>
</tbody>
$rs = mysql_query("SELECT * FROM test_work");
$results = [];
$days = [];
while ($row = mysql_fetch_assoc($rs)) {
$code = $row['code'];
if (!isset($results[$code])) {
$results[$code] = [
'day0' => '-',
'day1' => '-',
];
}
$results[$code]['day' . $row['day']] = $row['time'];
$results[$code]['' . $row['time']] = $row['day'];
}
$time = array(
't-1' => "09:30 A.M. - 10:30 A.M.",
't-2' => "10:40 A.M. - 11:40 A.M.",
't-3' => "11:50 A.M. - 12:50 P.M.",
't-4' => "03:30 P.M. - 04:30 P.M.",
't-5' => "04:45 P.M. - 06:00 P.M.",
't-6' => "06:10 P.M. - 07:10 P.M.",
't-7' => "05:30 P.M. - 06:30 P.M.",
't-8' => "06:50 P.M. - 07:50 P.M.",
);
?>
<table>
<thead>
<tr id="grey">
<th rowspan="2">Day0</th>
<th rowspan="2">Day1(s)</th>
<th rowspan="2">code</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $code => $result) : ?>
<!--You shouldn't have multiple elements using the same ids-->
<tr>
<?php $d0 = $result['day0'];
$d1 = $result['day1'];
?>
<td id='clist'><?php echo $time[$d0]; ?></td>
<td id='clist'><?php echo $time[$d1]; ?></td>
<td id='clist'><?php echo $code ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
$rs=mysql\u查询(“从测试工作中选择*);
$results=[];
$days=[];
while($row=mysql\u fetch\u assoc($rs)){
$code=$row['code'];
如果(!isset($results[$code])){
$results[$code]=[
“day0'=>”-',
“第1天”=>“-”,
];
}
$results[$code]['day.$row['day']]=$row['time'];
$results[$code]['.$row['time']]=$row['day'];
}
$time=array(
“t-1”=>“上午9:30-上午10:30”,
“t-2”=>“上午10:40-上午11:40”,
“t-3”=>“上午11:50-下午12:50”,
“t-4”=>“下午3:30-04:30”,
“t-5”=>“下午4:45-06:00”,
“t-6”=>“下午06:10-07:10”,
“t-7”=>“下午5:30-06:30”,
“t-8”=>“下午06:50-07:50”,
);
?>
第0天
第1天(s)
代码