我试图从mysql中的数据库中获取图像,然后在3行等中水平显示它们,我还希望将相关图像显示在图像的顶部。我不知道该怎么做。在我的主要部分中看到我的代码。
beforeEach(() => {
addProviders([
{provide: Router, useClass: MockRouter}
])
});
这是我的 php查询,我觉得这很好。
<div class="container" id="content">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-4">
<?php do { ?>
<a href="missions.php?missions_id=<?php echo $rsMissions['missions_id']; ?>">
<img src="<?php echo $rsMissions['missions_image']; ?>" width="500px" height="350px" >
<p><?php echo $rsMissions['missions_name']; ?></p>
</a>
<?php } while ($rsMissions = mysqli_fetch_assoc($missions_query)) ?>
</div>
</div>
以下是相关div的 css
<?php
require_once('includes/dbconn.php');
$missions_sql = "SELECT missions_id, missions_name, missions_image FROM missions";
$missions_query = mysqli_query($dbconn, $missions_sql) or die(mysqli_error());
$rsMissions = mysqli_fetch_assoc($missions_query);
?>
答案 0 :(得分:2)
你必须把循环放在col-md-4类之前。否则div不会重复。你不能水平地获取你的图像。尝试下面的代码,它会很适合你。
<div class="container" id="content">
<!-- Example row of columns -->
<div class="row">
<?php do { ?>
<div class="col-md-4">
<a href="missions.php?missions_id=<?php echo $rsMissions['missions_id']; ?>">
<img src="<?php echo $rsMissions['missions_image']; ?>" width="500px" height="350px" >
<p><?php echo $rsMissions['missions_name']; ?></p>
</a>
</div>
<?php } while ($rsMissions = mysqli_fetch_assoc($missions_query)) ?>
答案 1 :(得分:0)
我认为你把代码放在了错误的地方。如果有效,请尝试更改下面的代码。
function handleKeydown(e) {
// Allow: backspace, delete, tab, escape, enter and .
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
// Allow: Ctrl+A, Command+A
(e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) ||
// Allow: home, end, left, right, down, up
(e.keyCode >= 35 && e.keyCode <= 40)) {
// let it happen, don't do anything
return;
}
// Ensure that it is a number and stop the keypress
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
}
$('#content')
.html('Label 1: <input name="quantity[]" class="quantity"> Label 2: <input name="quantity[]" class="quantity">')
.find(".quantity")
.keydown(handleKeydown);
答案 2 :(得分:0)
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'ledp';
//create connection
$conn = new mysqli($servername,$username,$password,$dbname);
//check connection
if($conn->connect_error) {
die ('Error: Failed to connect database'.$conn->connect_error);
}
if(isset($_POST['submit5'])) {
$pro_image = $_FILES['pro_image'];
$tmp = $_FILES['pro_image']['tmp_name'];
$name = $_FILES['pro_image']['name'];
move_uploaded_file($tmp,'upload/'.time().$name);
if($name = '') {
echo 'Image upload failed';
} else {
echo 'Image uploaded';
}
}
$files = glob('upload/*.*');
//loop
$i;
for($i=0;$i<count($files);$i++){
$image = $files[$i];
echo basename($image);
echo '<div class="container-fluid">';
echo '<div class="row">';
echo '<div class="col-3 d-flex">';
echo '<img class="img-fluid" src="'.$image.'" alt="" width = 300px>'.'<br><br>';
echo '</div>';
echo '</div>';
echo '</div>';
};
echo "<h2>Total images: $i </h2>";
$conn->close();
?>