使用PHP在每列中显示和插入2个图像

时间:2017-08-27 19:10:00

标签: php html mysql

我想在2列中显示2张图片。 column1 中的第一个图像正在运行,image1正在显示,但在 column2 column2 不起作用

这里是2列中2幅图像的截屏:

Here's the screen capture of the 2 images in 2 column

这是结构:

// fetch.php

<?php
include('db.php');
include('function.php');
$query = '';
$output = array();
$query .= "SELECT * FROM rooms ";
if(isset($_POST["search"]["value"]))
{
 $query .= 'WHERE title_room LIKE "%'.$_POST["search"]["value"].'%" ';
}
if(isset($_POST["order"]))
{
 $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' ';
}
else
{
 $query .= 'ORDER BY id DESC ';
}
if($_POST["length"] != -1)
{
 $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row)
{
 $image = '';
 if($row["image"] != '')
 {
  $image = '<img src="upload/'.$row["image"].'" class="img-thumbnail" width="50" height="35" />';
 }
 else
 {
  $image = '';
 }
  $image1 = '';
 if($row["image2"] != '')
 {
  $image1 = '<img src="upload/'.$row["image2"].'" class="img-thumbnail" width="50" height="35" />';
 }
 else
 {
  $image1 = '';
 }

 $sub_array = array();
 $sub_array[] = $image;
 $sub_array[] = $image1;
 $sub_array[] = $row["title_room"];
 $sub_array[] = $row["Bed"];
 $sub_array[] = $row["occupancy"];
 $sub_array[] = $row["rate"];
 $sub_array[] = $row["room_size"];
 $sub_array[] = $row["type"];
 $sub_array[] = $row["description"];
 $sub_array[] = '<button type="button" name="update" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Update</button>';
 $sub_array[] = '<button type="button" name="delete" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Delete</button>';
 $data[] = $sub_array;
}
$output = array(
 "draw"    => intval($_POST["draw"]),
 "recordsTotal"  =>  $filtered_rows,
 "recordsFiltered" => get_total_all_records(),
 "data"    => $data
);
echo json_encode($output);
?>

// fetch_single.php

<?php
include('db.php');
include('function.php');
if(isset($_POST["user_id"]))
{
 $output = array();
 $statement = $connection->prepare(
  "SELECT * FROM rooms
  WHERE id = '".$_POST["user_id"]."' 
  LIMIT 1"
 );
 $statement->execute();
 $result = $statement->fetchAll();
 foreach($result as $row)
 {
  $output["text_name"] = $row["title_room"];
  $output["text_bed"] = $row["Bed"];
  $output["text_occupancy"] = $row["occupancy"];
  $output["text_rate"] = $row["rate"];
  $output["text_size"] = $row["room_size"];
  $output["text_type"] = $row["type"];
  $output["text_description"] = $row["description"];
  if($row["image"] != '')
  {
   $output['user_image'] = '<img src="upload/'.$row["image"].'" class="img-thumbnail" width="50" height="35" /><input type="hidden" name="hidden_user_image" value="'.$row["image"].'" />';
  }
  else
  {
   $output['user_image'] = '<input type="hidden" name="hidden_user_image" value="" />';
  }

  if($row["image2"] != '')
  {
   $output['user_image1'] = '<img src="upload/'.$row["image2"].'" class="img-thumbnail" width="50" height="35" /><input type="hidden" name="hidden_user_image1" value="'.$row["image2"].'" />';
  }
  else
  {
   $output['user_image1'] = '<input type="hidden" name="hidden_user_image1" value="" />';
  }
 }
 echo json_encode($output);
}
?>

// function.php

<?php

function upload_image()
{
 if(isset($_FILES["user_image"]))
 {
  $extension = explode('.', $_FILES['user_image']['name']);
  $new_name = rand() . '.' . $extension[1];
  $destination = './upload/' . $new_name;
  move_uploaded_file($_FILES['user_image']['tmp_name'], $destination);
  return $new_name;
 }

 if(isset($_FILES["user_image1"]))
 {
  $extension1 = explode('.', $_FILES['user_image1']['name']);
  $new_name1 = rand() . '.' . $extension1[1];
  $destination1 = './upload/' . $new_name1;
  move_uploaded_file($_FILES['user_image1']['tmp_name'], $destination1);
  return $new_name1;
 }
}

function get_image_name($user_id)
{
 include('db.php');
 $statement = $connection->prepare("SELECT image, image2 FROM rooms WHERE id = '$user_id'");
 $statement->execute();
 $result = $statement->fetchAll();
 foreach($result as $row)
 {
  return $row["image"];
 }
}

function get_total_all_records()
{
 include('db.php');
 $statement = $connection->prepare("SELECT * FROM rooms");
 $statement->execute();
 $result = $statement->fetchAll();
 return $statement->rowCount();
}

?>

//这是我在index.php中的输入

<label>Select Room Image</label>
     <input type="file" name="user_image" id="user_image" />
     <span id="user_uploaded_image"></span>
     <br />
     <label>Select Room Image(1)</label>
     <input type="file" name="user_image1" id="user_image1" />
     <span id="user_uploaded_image1"></span>
    </div>
    <div class="modal-footer">
     <input type="hidden" name="user_id" id="user_id" />

这是针对学校项目的。

0 个答案:

没有答案