no errors just i have not move images up
@cootheadâs code produces this:
On narrower screens, it behaves like this:
Those images are at the top of the posts, as you said you wanted. If we have not understood your requirements, then please explain how they differ from the result here.
I want same like that
OK. The code which coothead posted above does exactly that.
If it does not behave the same way when you try to add it to your site, then either you have made a mistake, or there is some other rule conflicting with the styles.
Without seeing the exact, full HTML and CSS which you are using, we canât diagnose the problem.
did you see code up for name and comment i am using mysql to enter and display from mysql can you make some php which will display images by side name an comment ,like on link.
PHP does not control the positioning; CSS does.
i tried css didnt work what want put image in div and direct styling for that div
What was the CSS you tried?
mydiv4 i did try to add didnt work
I see nothing with a class of mydiv4 anywhere in either your code or cootheadâs, so that still tells us nothing. We donât know what code you added, or where you added it to.
anybody using team too much code to paste here
If you want people to help, youâre going to have to put in some effort to help people to help you. @coothead gave you a good solution which works fine as it is but when added to your page doesnât work - so it is up to you to show us what extra HTML and CSS you have that stops @cootheadâs page from working.
ok lets do it this way
<?php
// Create database connection
$db = mysqli_connect("localhost", "root", "", "image_upload");
// Initialize message variable
$msg = "";
// If upload button is clicked ...
if (isset($_POST['upload'])) {
// Get image name
$image = $_FILES['image']['name'];
// Get text
$image_text = mysqli_real_escape_string($db, $_POST['image_text']);
// image file directory
$target = "images/".basename($image);
$sql = "INSERT INTO images (image, image_text) VALUES ('$image', '$image_text')";
// execute query
mysqli_query($db, $sql);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "Image uploaded successfully";
}else{
$msg = "Failed to upload image";
}
}
$result = mysqli_query($db, "SELECT * FROM images");
?>
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
<style type="text/css">
#content{
width: 50%;
margin: 20px auto;
border: 1px solid #cbcbcb;
}
form{
width: 50%;
margin: 20px auto;
}
form div{
margin-top: 5px;
}
#img_div{
width: 80%;
padding: 5px;
margin: 15px auto;
border: 1px solid #cbcbcb;
}
#img_div:after{
content: "";
display: block;
clear: both;
}
img{
float: left;
margin: 5px;
width: 300px;
height: 140px;
}
</style>
</head>
<body>
<div id="content">
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
echo "<img src='images/".$row['image']."' >";
echo "<p>".$row['image_text']."</p>";
echo "</div>";
}
?>
<form method="POST" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea
id="text"
cols="40"
rows="4"
name="image_text"
placeholder="Say something about this image..."></textarea>
</div>
<div>
<button type="submit" name="upload">POST</button>
</div>
</form>
</div>
</body>
</html>
<form method="POST" action="index.php" enctype="multipart/form-data">
i want put by side of the submit insert in db image and display from db.But name and comment and image must be same like id who entered.So if i insert name i wanna see imy mage .
Hit here capljina2,
if itâs any help, all I did was remove each imageâŚ
<img class="comment-avatar pull-left"
âŚwhich was just afterâŚ
<div class="comment">
âŚand then put placed it just afterâŚ
<div class="comment-content">
I can assure you that, absolutely no rocket science
was used during the procedure,
coothead
hmmmm
do you have team viewer
I doubt many people do, and it is not in the spirit of the forums in any case, where discussions are all public.
As has been mentioned before, it is your HTML and CSS that we need to see, not your PHP/MySQL.
Yes, this question is about layout, so CSS is the solution. The logical approach would be to come up with some css and html code which works to display the layout as you intend (like @coothead provided).
Only once you have that working, then adjust your PHP script so that it creates that html code with the appropriate classes on the various elements for the css to work.
Viewing the php at this stage is just a complication which distracts from working out the problem in pure html/css.
i have error on this code syntax error
echo '<img class="comment-avatar pull-left" '.( !empty( $images[$count] ) ? alt="" '<img src="images/blog/'.$images[$count].'">' : '')
how echo this Preformatted text
<img class=âcomment-avatar pull-leftâ â.( !empty( $images[$count] ) ? ââ : ââ).â Preformatted text
You are missing a single quote before alt=
But thatâs not to any help for us to help.