PHP代码
<?php
include("connect.php")
$activityid = "select activity.activity_name,activity.activity_id
from activity
join serviceactivitymap on activity.activity_id = serviceactivitymap.activity_id
where serviceactivitymap.service_id = 1";
$activityvalue = $conn->query($activityid) or die ($conn>error.__LINE__);
$activities = [];
while ($row = $activityvalue->fetch_assoc()) {
$activities[] = $row;
}
$serviceid = "select * from service";
$servicevalue = $conn->query($serviceid) or die ($conn->error.__LINE__);
$services = [];
while ($row = $servicevalue->fetch_assoc()) {
$services[] = $row;
}
foreach ($services as $service):
?>
<form action = "index.php method = "post">
<input name='serviceone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $service['service_id']?>"/><?php echo $service['service_name']?>
<br>
<?php foreach ($activities as $activity):?>
<input name='activityone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $activity['activity_id']?>"/><?php echo $activity['activity_name']?>
<br>
<?php endforeach ?>
<?php endforeach ?>
</form>
代码输出为:
我有3个表services
,activity
,serviceactivitymap
我将service_id
,service_name
存储在服务中,并将activity_id
,activity_name
存储在活动中,并将service_id
和相关的activity_id in
serviceactivitymap but i dont know how to display related activities under services.
`表结构是
Gst
税款支付
法定审计
Tds
内部审核
库存审核
我可以这样显示吗?
答案 0 :(得分:0)
<?php include("connect.php")?>
<?php
$activityid = "select activity.activity_name,activity.activity_id
from activity
join serviceactivitymap on activity.activity_id = serviceactivitymap.activity_id
where serviceactivitymap.service_id = 1";
$activityvalue = $conn->query($activityid) or die ($conn>error.__LINE__);
$activities = [];
while ($row = $activityvalue->fetch_assoc()) {
$activities[] = $row;
}
$serviceid = "select * from service";
$servicevalue = $conn->query($serviceid) or die ($conn->error.__LINE__);
$services = [];
while ($row = $servicevalue->fetch_assoc()) {
$services[] = $row;
}
foreach ($services as $service):
?>
<form action = "index.php" method = "post">
<input name='serviceone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $service['service_id']?>"/><?php echo $service['service_name']?>
<br>
<?php foreach ($activities as $activity):?>
<input name='activityone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $activity['activity_id']?>"/><?php echo $activity['activity_name']?>
<br>
<?php endforeach ?>
<?php endforeach ?>
</form>
你去了。您在表单操作中缺少右引号