저는 데이터베이스에서 학생 작품을 가져와야하는 학교 프로젝트를 수행하고 있습니다.mysql은 각 데이터가 새로운 행을 추가 할 때마다 데이터를 검색합니다.
내 홈페이지에는 쿼리에서 반환 된 데이터를 보유 할 수 있도록 사전 설정이 10 개 있습니다. 난 단지 10 데이터를 검색 할 필요가 있기 때문에 나는 그것을 미리 설정합니다.
HTML은 다음
<div class="viewport-computer col-lg-12 visible-lg no-padding ">
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
<div class="col-lg-2 img_thumb_holder no-padding">
<img class="img_thumb">
<h2 class="caption">Author<br />Description</h2>
</div>
</div>
는 나는 내가 루프 때문에 잘 작동하고 다시 10 개 데이터를 가져 오기 위해 내 PHP로 조회 할 수 jQuery를 사용하여 내 10 사업부에
jQuery를
/* Home Page Autoload featured thumbnails based on computer viewport/mobile viewport
================================================== */
$.ajax({
type: "POST",
dataType: "json",
url: "CMS/PHP/displayFeatThumbs.php",
success: function(data) {
// Display image thumbnail, caption & description of works onto each thumbnail div
$('.viewport-computer .img_thumb_holder img').each(function(index, element) {
// Work out the data to set
var imageUrl = "cms/" + data[index].links;
var captionHtml = "<span>" + data[index].caption + "<span class='spacer'></span><br/><span class='spacer'></span>" + data[index].title + "</span>"
// Now apply this to the elements
$(element).attr("src", imageUrl); // i must find a way to solve this
$(element).parent().css('background-image', 'url("'+imageUrl+'")');
$(element).next().html(captionHtml);
// push the caption & id into global variable array to be used on other functions easily
captionArray.push(data[index].caption);
idArray.push(data[index].id);
homeLinksArray.push(data[index].links);
homeTitleArray.push(data[index].title);
});
});
를 배치 내 미리 설정된 div (10 개)를 통해 다음 각 div에 데이터를 배치합니다. 이제 검색 막대 기능을 수행해야하며 모든 결과 (50 개 이상)를 반환합니다. 그들, 이제 문제는 내가 단지 사전 10divs, 그래서 내 흐름이
좋은 그래서 대신 아니라고 내 현재
loop through 10 div > retrieve data and place on 10 div
내가 PHP와 아주 좋은 아닙니다에
retrieve all data, for each data, append a new div and place it
싶습니다 저는 아직 새로운 학습자입니다. 그래서 어떻게 할 지에 대한 아이디어를 가지고 있지만, 저는 그것에 매달 렸습니다. 누군가가 각 데이터를 반복 할 수있는 방법을 알려주고 사전 설정 div 대신에 추가 할 수 있습니까?
PHP
<?php
include 'dbAuthen.php';
$searchBar = $_POST['searchBar'];
$sql = "SELECT userdatafiles.UserID,Name,Link,Title FROM userdatafiles JOIN users ON userdatafiles.UserID = users.UserID WHERE Skillsets = '$searchBar' GROUP BY UserID ORDER BY RAND()";
$result = mysqli_query($con,$sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo '<div>hi</div>',
$links[] = array(
"id" => $row["UserID"],
"links" => $row["Link"],
"caption" => $row["Name"],
"title" => $row["Title"],
);
}
//shuffle($links);
echo json_encode($links);
} else {
echo "0 results";
}
?>
감사 형제는, 내가 찾고 있어요 모두가 내가
당신이 이미 1 & 2를 수행 오신 것을 환영합니다 :) –