简体   繁体   English

打印未知/随机的帖子ID

[英]Print unknown / random post id's

I am trying to work out a problem I am having with a photo selection script. 我正在尝试解决照片选择脚本遇到的问题。 How it works is the user is presented with a page of thumbnails, each thumbnail has a check box under it. 它的工作方式是向用户显示一个缩略图页面,每个缩略图下方都有一个复选框。 If the user wants to order that photo they click the checkbox. 如果用户要订购该照片,请单击该复选框。 The problem I am having is im not sure how to echo the photos out, as each of the photos is given a random name when uploaded. 我遇到的问题是我不确定如何回显照片,因为每张照片在上传时都被赋予了随机名称。

For example on the page I clicked 4 photos and then hit submit, I then echo'd out all of the post data which gives me : 例如,在页面上,我单击了4张照片,然后单击“提交”,然后回显了所有发给我的帖子数据:

Array ( [984321568417_jpeg] => on [380737457699_jpeg] => on [632283404882_jpeg] => on [859974304006_jpeg] => on [albumname] => Ben & Katie [submit] => Submit )

so......if I want to put the album name into the database that's easy enough I just use 所以......如果我想将专辑名称放到数据库中就足够简单了,我就用

  $_POST['albumname']

but I have no idea how to collect the image names from the checkboxes as the id of the posted data depends on the name of the image ?. 但是我不知道如何从复选框中收集图像名称,因为发布的数据的ID取决于图像的名称?

      echo '<h1>'.$albumname.'</h1>';
      echo '<p style="clear:both; float:none;">(Click an image to enlarge, select the tick box under an image to add it to the album)</p>';

  $sql2 = <<<SQL
      SELECT *
      FROM `albums`
      WHERE albumid = '$albumid' AND isalbum = ''
  SQL;


  if(!$result2 = $db->query($sql2)){
      die('There was an error running the query [' . $db->error . ']');
  }
  while($row2 = $result2->fetch_assoc()){

      echo '<div class="imagewrapper">';
      echo '<a title="'.$row2['id'].'" class="fancybox-thumb" rel="fancybox-thumb" href="albums/'.$albumid.'/800x600/'.$row2['image'].'"><img style="border-radius:5px;" src="albums/'.$albumid.'/thumbnails/'.$row2['image'].'" /></a>';
        echo '<div style="text-align:center;">';
        echo '<strong>Select : </strong><input class="selectcheckbox" type="checkbox" name="'.$row2['image'].'" id="check_'.$row2['id'].'" />';
        echo '</div>';
        echo '</div>';
      }
  ?>
  <script>

EDIT>>>>>>>>>>> 编辑>>>>>>>>>>>

Ok I have now added 'check_' to the start of each of the checkbox titles so I now get the following post data , so im not sure if I can put something like (put all posted data containing 'checked_' into an array on its own ?). 好的,我现在在每个复选框标题的开头都添加了“ check_”,因此我现在获得以下发布数据,所以不确定是否可以将类似(将所有包含“ checked_”的发布数据放入其数组中拥有 ?)。

Array ( [check_380737457699_jpeg] => on [check_632283404882_jpeg] => on [albumname] => Ben & Katie [submit] => Submit )

Change your checkboxes to: 将您的复选框更改为:

<input type="checkbox" name="photos[]" value="380737457699_jpeg">

Then you can var_dump($_POST['photos']) to output something similar to: 然后,您可以var_dump($_POST['photos'])输出类似于:

array(
  [0] => 380737457699_jpeg
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM