displaying image in php mysql
8 posts
Page 1 of 1
hello,
can anyone help me please i want to check to make sure that the image exists if it dosent dont display an image if it does exist then display the image this is the line of code.
can anyone help me please i want to check to make sure that the image exists if it dosent dont display an image if it does exist then display the image this is the line of code.
Code: Select all
Full Page Code:-<img src="../news_pics/<?php echo $post_image; ?>" width="100" height="100">
Code: Select all
<?php include('styles/top.php'); ?>
<div id="left">
<?php
include("includes/connect.php");
$select_posts = "SELECT * FROM news ORDER BY post_id DESC LIMIT 1";
$run_posts = mysql_query($select_posts);
while($row=mysql_fetch_array($run_posts)){
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_date = $row['post_date'];
$post_author = $row['post_author'];
$post_image = $row['post_image'];
$post_content = substr($row['post_content'],0,200);
?>
<h2>
<a href="pages.php?id=<?php echo $post_id; ?>">
<?php echo $post_title; ?>
</a>
</h2>
<p align="left">Published on: <b><?php echo $post_date; ?></b></p>
<p align="right">Posted by: <b><?php echo $post_author; ?></b></p>
<center><img src="news_pics/<?php echo $post_image; ?>" width="500" height="300" /></center>
<p align="justify"><?php echo $post_content; ?></p>
<p align="right"><a href="pages.php?id=<?php echo $post_id; ?>">Read More</a></p>
<hr>
<?php } ?>
</div>
<?php include('styles/bottom.php'); ?>
Code: Select all
<?
$path = "../path/to/image";
echo "<img src=\"".(file_exists($path)) ? $path : "path/to/default" . "\" />";
?>
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo![]()
hello,
i tried this but it only shows the name of the image that should be there and not the image.
i tried this but it only shows the name of the image that should be there and not the image.
Code: Select all
<?
$path = "../news_pics/$post_image";
echo "<img src=\"".(file_exists($path)) ? $path : "" . "\" />";
?>
Mark wrote:hello,Sorry, I've been typing this code on a mobile phone so I left out parenthesis..
i tried this but it only shows the name of the image that should be there and not the image.
Code: Select all<? $path = "../news_pics/$post_image"; echo "<img src=\"".(file_exists($path)) ? $path : "" . "\" />"; ?>
The code should be:
Code: Select all
KR, <?
$path = "../news_pics/$post_image";
echo "<img src=\"".((file_exists($path)) ? $path : "") . "\" />";
?>
-Filip
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo![]()
how would i set the size of the image?.
Add style="width: 123px" attribute into the img tag
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo![]()
where does it go in the code.
<?
$path = "news_pics/$post_image";
echo "<img src=\"".((file_exists($path)) ? $path : "") . "\" />";
?>
<?
$path = "news_pics/$post_image";
echo "<img src=\"".((file_exists($path)) ? $path : "") . "\" />";
?>
Code: Select all
<?
$path = "news_pics/$post_image";
echo "<img style=\"width: 123px;\" src=\"".((file_exists($path)) ? $path : "") . "\" />";
?>
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo![]()
8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023