如何使用数据库和php显示服务下的相关活动

时间:2018-08-20 12:15:33

标签: php sql

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>

代码输出为:

  • 所得税
    • 修改后的填充
    • 退货
  • Gst
    • 修改后的填充
    • 退货
  • Tds
    • 修改后的填充
    • 退货

我有3个表servicesactivityserviceactivitymap 我将service_idservice_name存储在服务中,并将activity_idactivity_name存储在活动中,并将service_id和相关的activity_id in serviceactivitymap but i dont know how to display related activities under services. `表结构是

  • 所得税
    • 修改后的填充
    • 退货
  • Gst

    • 税款支付

    • 法定审计

  • Tds

    • 内部审核

    • 库存审核

我可以这样显示吗?

1 个答案:

答案 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>

你去了。您在表单操作中缺少右引号