如何在HTML和PHP中将URL存储为弹出窗口的数组中显示图像
我现在有一些PHP,可以在表中显示搜索查询的信息,我有一个curl连接,连接到web应用程序,返回图像的URL并将其存储在数组中 当您将鼠标悬停在桌子上时,如何使图像显示为弹出窗口 目前,我可以使一个图像出现,但不是所有的,有时图像的网址将是正确的,但会显示错误 理想的结果是将鼠标悬停在表格上,并在鼠标悬停在该表格上时查看剪切的缩略图等 这是我的密码如何在HTML和PHP中将URL存储为弹出窗口的数组中显示图像,php,html,Php,Html,我现在有一些PHP,可以在表中显示搜索查询的信息,我有一个curl连接,连接到web应用程序,返回图像的URL并将其存储在数组中 当您将鼠标悬停在桌子上时,如何使图像显示为弹出窗口 目前,我可以使一个图像出现,但不是所有的,有时图像的网址将是正确的,但会显示错误 理想的结果是将鼠标悬停在表格上,并在鼠标悬停在该表格上时查看剪切的缩略图等 这是我的密码 <?php function getHitInfos($hits) { return [ "url"
<?php
function getHitInfos($hits)
{
return [
"url" => $hits->thumbnailUrl
// "name" => $hits->metadata->baseName
];
}
function getimageURL($results, $hits)
{
return [
"url" => $hits->thumbnailUrl
];
foreach ($results as $key => $val) {
return "<img src='" . $val["url"] . "class='hide-image' alt='error'/>";
// "<img src=".getimageURL($hits)." class='hide-image' />
// echo $val["name"];
}
}
function printResultsB($results) {
// echo "".$title."";
foreach ($results as $key => $val) {
return"<img src='" . $val["url"] . "'class='hide-image' alt='error'>";
}
}
if (isset($_POST['search'])) {
// SEARCH FOR ITEMS
require "2-search.php";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>Item number</th>";
echo "<th>Stock available</th>";
echo "<th>Available Stock</th>";
echo "<th>Brand name</th>";
echo "<th>Detailed Description</th>";
echo "<th>Division</th>";
echo "<th>Gender</th>";
echo "<th>Group</th>";
echo "<th>Subgroup</th>";
echo "</tr>";
echo "</thead>";
foreach ($resultsArray as $key => $results) {
if (count($results) > 0) {
foreach ($results as $r) {
$username = 'username';
$password = 'password';
$loginUrl = 'www.login.com';
//init curl
$ch = curl_init();
//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$username.'&password='.$password);
//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute the request (the login)
$store = curl_exec($ch);
//the login is now done and you can continue to get the
//protected content.
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'https://website'. $r['item_number'] .'');
//WORKS
$content = curl_exec($ch);
$data = json_decode($content);
$hits = $data->hits;
// echo "Number of images found: ".$data->totalHits."<br>";
$creative = [];
$styled = [];
$group = [];
$cutout = [];
$worn = [];
$other = [];
foreach ($hits as $hit)
{
$target = $hit->metadata->baseName;
$target1 = $hit->metadata->cf_imageType;
if(preg_match("/_SH/i",$target)) {
$group[] = getHitInfos($hit);
}
elseif(preg_match("/_cm|_cd|_cb/i",$target)) {
$creative[] = getHitInfos($hit);
}
elseif(preg_match("/_SS/i",$target)) {
$styled[] = getHitInfos($hit);
}
elseif(preg_match("/still life/i",$target1) && preg_match("/_sm_00|_sd_00/i",$target)) {
$cutout[] = getHitInfos($hit);
}
elseif(preg_match("/worn/i",$target1)) {
$worn[] = getHitInfos($hit);
}
else{
$other[] = getHitInfos($hit);
}
// print_r($cutout);
// printResultsC($cutout, 'Cutout');
}
curl_close($ch);
echo "<tbody>";
echo "<tr>";
echo "<td>". $r['item_number'] ."</td>";
echo "<td>". $r['image_in'] ."</td>";
//DISPLAY IMAGE (ODD QUIRK WILL ERROR FOR FIRST PHOTO BUT NOT THE REST ?)
// echo "<td>Cutout: " .count($cutout)."<br>Worn:".count($worn)."<br>Styled:".count($styled)."<br>Group:".count($group)."<br>Creative:".count($creative)."<br>Other:".count($other)."</td>";
echo "<td><a href='#' class='preview'>Cutout: " .count($cutout)."<br>Worn:".count($worn)."<br>Styled:".count($styled)."<br>Group:".count($group)."<br>Creative:".count($creative)."<br>Other:".count($other)."".printResultsB($cutout)."</a></td>";
echo "<td>". $r['DelQty'] ."</td>";
echo "<td>". $r['Date_Due'] ."</td>";
echo "<td>" . $r['outlet_selling_route']. "</td>";
echo "<td>" . $r['internet_item_type'] . "</td>";
echo "<td>" . $r['division'] . "</td>";
echo "<td>" . $r['gender'] . "</td>";
echo "<td>" . $r['grp'] . "</td>";
echo "</tr>";
echo "</tbody>";
}
} else {
echo " No results found for ". $searchFor[$key];
}
}
}
echo "</table>";
?>
.hide-image {
display: none;
z-index: 100;
position: absolute;
}
.preview:hover .hide-image {
display: block
}