在功能内打印URL链接

时间:2020-05-04 17:25:37

标签: php arrays

我正在创建电影数据库。我需要查看,编辑和删除才能链接到站点中的其他页面。例如,我希望视图转到名为show.php的链接,但我需要页面动态加载$ movie [id]信息。我如何从函数中做到这一点。这是我到目前为止的内容:

  printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
      $movie['id'],
      $movie['title'],
      $movie['director'],
      $movie['year'],
      printDropdown ($movie['cast']),
      '<img src="'.$movie ['poster'].'" height="100" width="75"/>',
      '<a class="action" href="">'.'View'.'</a>',
      '<a class="action" href="">'.'Edit'.'</a>',
      '<a class="action" href="">'.'Delete'.'</a>',
 );
}

于5/12修改: 我决定采用其他方法。海报列显示在表中,但即使URL图像源对于每个阵列都是正确的,它也显示所有图像均已损坏。包含图像源的表格列中缺少什么?

<?php foreach($movies as $movie) { ?>
  <tr>
    <td><?php echo h($movie['id']); ?></td>
    <td><?php echo h($movie['title']); ?></td>
    <td><?php echo h($movie['director']); ?></td>
    <td><?php echo h($movie['year']); ?></td>
    <td><?php echo printDropdown($movie['cast']); ?></td>
    <td><img src="'.$movie['poster'].'" height="100" width="75"/></td>
    <td><a class="action" href="<?php echo url_for('show.php?id=' . h(u($movie['id']))); ?>">View</a></td>
    <td><a class="action" href="<?php echo url_for('edit_movie.php?id=' . h(u($movie['id']))); ?>">Edit</a></td>
    <td><a class="action" href="">Delete</a></td>
  </tr>
<?php } ?>
</table>

2 个答案:

答案 0 :(得分:1)

阅读PHP GET。而且您应该能够做到。

您必须执行以下操作:

 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
      $movie['id'],
      $movie['title'],
      $movie['director'],
      $movie['year'],
      printDropdown ($movie['cast']),
      '<img src="'.$movie ['poster'].'" height="100" width="75"/>',
      '<a class="action" href="show.php?action=view&id=' . $movie['id'] . '">'.'View'.'</a>',
      '<a class="action" href="">'.'Edit'.'</a>',
      '<a class="action" href="">'.'Delete'.'</a>',
 );

在另一页中。像show.php一样,您可以获取给定的操作和ID,例如:

$id = $_GET['id']; // the given id
$action = $_GET['action']; // view

答案 1 :(得分:0)

您可以使用GET method

在这种情况下,您将参数放置在href属性的url中。喜欢:

<a href='<url>?movie_id={$movie['id']}&title={$movie['title']}'>
相关问题