i have images in my blob field in database i use blow colde for displaying image but
it does not show any pic , someone could tell me where is my wrong?
this is my model:
public function getListUser() {
$select = $this->select()
->order('lastname DESC');
$adapter = new Zend_Paginator_Adapter_DbTableSelect ($select);
return $adapter;
}
this my controller:
$userModel = new Admin_Model_User();
$adapter = $userModel->getListUser();
$paginator = new Zend_Paginator ($adapter);
$paginator->setItemCountPerPage(1);
$page = $this->_request->getParam('page', 1);
$paginator->setCurrentPageNumber($page);
$this->view->paginator = $paginator;
this my view code:
<td style="width: 20%;"> <?php
echo $this->lastname ?> </td>
<td style="width: 20%;"><?php header("Content-type: image/gif"); print $this->image; ?></td>
This is not how you can display your image.
Your code should look something like this.
<td style="width: 20%;"> <?php
echo $this->lastname ?> </td>
<td style="width: 20%;"><img src="/link-to-php-that-shows-image.php?id=123" /></td>
Now, in the php file for example (link-to-php-that-shows-image.php). You get the image field from the database and display it. Example..
<?php
$image = //get image from database, based on id etc.
header("Content-type: image/gif");
print $image;
?>
You cannot do this line of code.
<td style="width: 20%;">
<?php header("Content-type: image/gif"); print $this->image;?>
</td>
It's because, <td style="width: 20%;"> is html element which gets printed before image is outputed and headers are send to output image, so you get error
Error:: Cannot modify header information - headers already sent by ..
But you don't get this error in zend framework because the error display might have been turned off, so have a look at your application.ini file for setting.
The best way to do this would be to store image in folders and store the filename or filepath in database and echo out something like
<td style="width: 20%;">
<img src="<?php echo $imagefullpath; ?>"/>
</td>
But if you still want to store image in database then, you can use ajax to load image. For further assistance, please comment.
For the beginners there is a very handy rule:
PHP can't do anything beside plain HTML can.
Now answer yourself a question:
would you see anything if you paste image file contents directly into HTML code?
And then another one
How do images being displayed in HTML?
And a final one:
are you sure you want to store images in the blob field in database?
Related
<section class="latest-news-index">
<table style="width: 100%; max-width: 100%;margin-bottom: 20px; "class="table table-hover ">
<tbody><tr><td style="border-bottom: 1px solid #9e9e9e;border-top: none;font-size: 2.1em;font-weight: bold;" colspan="99" class="date-header"><?php echo date('m.d.y');?></td></tr>
<?php
$sayfa = $news->pager($SAYFA,15,'haber','h_id',"WHERE onay='1' AND time<='".time()."'");
$sql = $db->sql(
"SELECT haber.h_id,
haber.k_id,
haber.baslik,
haber.baslik_renk,
haber.resim,
haber.k_icerik,
haber.link,
haber.time,
kategori.baslik as kategori
FROM haber
LEFT JOIN kategori ON haber.k_id=kategori.k_id
WHERE kategori.onay='1'
AND haber.onay='1'
AND DATE(FROM_UNIXTIME(haber.time)) = DATE(SYSDATE())
ORDER BY haber.time DESC
"
);
if($db->num_rows($sql)>0):
$i = 1;
while($data = $db->f_array($sql)):
$id = $news->dataview($data['h_id']); // news id
$baslik = $news->dataview($data['baslik']); // news title
$baslik_renk= ($news->dataview($data['baslik_renk']) ? ' style="color:'.$news->dataview($data['baslik_renk']).';"' : ''); // title color
$resim = $news->dataview($data['resim']); // news image
$kIcerik = $news->dataview($data['k_icerik']); // News desc
$time = $news->dataview($data['time']); // News date
$kategori = $news->dataview($data['kategori']); // category
$haberlink = $news->dataview($data['link']); // seo_link
$link = ($haberlink == '' ? $news->url('haber',$id,$baslik) : $haberlink); // generation link
$photo = $news->dataview($data['fg_id']); // getting photo gallery id for news content
$video = $news->dataview($data['vd_id']); // getting video id for news content
?>
<tr class="item">
<?php if($sistem['iceriktarih']): ?>
<td class="time"><?=$news->saat($time)?></td>
<?php endif; ?>
<td class="category"><?=$kategori?> </td>
<td class="title"><b><?=$baslik?><span class="title-icons"></span></b></td>
</tr>
<?php
endwhile;
endif;
?>
</tbody></table>
</section>
Hello friends,
My system has: video, photo, "breaking news"
This is how my system should work:
If news has video it should have video Icon.
If news has photo gallery it should have photo icon.
Can someone help me with this?
Thanks in advance.
#ReshoMarcos that screenshot helped alot. But still i dont know about
your data structure and other sutff, so i cant help you finding the
flag. You may even need to change your database to be able to have
that flag. But after you had flag you can use the answer i gave you
OK with that screen shot you sent its more clear but still i dont know where you store the flag (the data you are gonna decide if the news has video or if it has image)
So as far as i see here is where you want to show the icons
<td class="title"><b>
<?=$baslik?><span class="title-icons">^^^^^^^here^^^^^</span>
</b></td>
So based on your flag. (the variable that holds data that can help you realize if new has image or video). So you may have the flag already stored in your database (like a filed in a table) or you may have to create the flag base on different conditions and checking the news' type or if video src filed in data base is empty or such things. So lets say you have your flag and it is name $newType or $newsHasVideo. So this is how your code should look like.
inside while loop after you set the variables:
<?php
$newsHasVideo= true; // or false i told you about the flag
if($newsHasVideo){
$icon = '<span class="icon vid-icon"></span>';
//$icon should be filled with real icon data based on your
// needs like glyph-icons or font-awesome
}else{
$icon = '<span class="icon img-icon"></span>';
}
?>
<tr class="item">
<?php if($sistem['iceriktarih']): ?>
<td class="time"><?=$news->saat($time)?></td>
<?php endif; ?>
<td class="category"><?=$kategori?> </td>
<td class="title"><b><?=$baslik?><span class="title-icons"><?php echo $icon; ?></span></b></td>
</tr>
I am trying to display image from a blob field of a MySQL table. Looks like I have some sort of error in the following line. As soon as I put "header("Content-type: image/jpeg")" things get messed up and instead of displaying webpage, all source code of the page is displayed.
Please let me know how to correct.
<div class="image" align="left">
<a href="<?php header("Content-type: image/jpeg"); echo $rec['image']; ?>">
<img src="<?php echo $rec['image']; ?>" width="150" border="0"/>
</a>
</div><!-- image -->
You normally don't put the actual image contents in the src= attribute of the image tag. Instead, you point to the URL of an image file.
(There are ways to include the image source directly in the HTML, but it doesn't work consistantly with all browsers, and you still won't have your <a> link working properly.
Instead, the best way to do this is to create a separate PHP file to serve the image.
Your HTML:
<div class="image" align="left">
<img src="myimage.php?key=<?php echo($key) ?>" width="150" border="0"/>
</div><!-- image -->
myimage.php:
<?php
header("Content-type: image/jpeg");
$key = $_GET['key'];
// todo: load image for $key from database
echo $rec['image'];
You're trying to put the image data inline inside the content. The only feasible way to do this is via a Data URI data URI. Something like:
<img src="data:image/jpeg;base64,<?= base64_encode($rec['image']) ?>" width="150" border="0" />
However, what you probably want to do is put it into a separate script. So your HTML would be:
<img src="showimage.php?id=XXX" width="150" border="0" />
And your showimage.php script would be:
<?php
// Get $rec from database based on the $_GET['id']
header('Content-Type: image/jpeg');
echo $rec['image'];
?>
I've done something like that retrieving blob from my database in another way that you may find useful, here is the code example.. see if it suits your needs and if you needed anymore help let me know.
while ($row = mysql_fetch_array($hc_query2)) {
$title = $row['title'];
$text = $row['text'];
$image = $row ['image'];
$output ='<div class="HCInstance"><img src="data:image/jpeg;base64,' . base64_encode($image) . '" alt="High Council" width="100px" height="100px"/>
<div class="HCHeader"><h2>'.$title.'</h2></div><br/><div class="HCDetails"><p>'.$text.'</p></div></div>';
echo $output;
}
The images are stored in my folder and not in database. When i click on one of the images, it will lead me to see more info on the next page. This would means that i can see the image with a bigger size.
How do I do this with less php pages created? Below are snippets of my codes
<table>
<tr>
<th class="timgB"><h4><img src="city/GVcementMixture.jpg" style="vertical-align: text-bottom;" title="Cement Mixture"/> Cement Mixture </a></h4></th>
</tr>
</table>
You could keep it all in one form/page with a big if/else or switch/case statement to evaluate the selected image and show only info pertaining to the selected image such as the full size image or a sub-set of child images. But it would be best presented in jQuery as #Razor said.
<form ...>
<button type=submit name=imgID value=1>
<button type=submit name=imgID value=2>
...
<?php
if (isset($_POST['imgID'])):
// Show info related to selected image
...
you can do it like this. use class="small for make image size small and class="big-img" to big size image. the ?img=img23.jpg in your link decide which image should be shown with big size. or if you use thumbnail of image as small size and want to show a full size only when some one click on thumbnail then update the link in upper div (class="big-img") or leave comment.
//it will work as you want
<body>
<div class = "big-img"> <!-- set class to show big size image-->
<?php if(isset($_GET['img'])): ?>
<img src="city/.<?php echo $_GET['img']; ?>" alt="">
<?php endif; ?>
</div>
<table>
<tr><!-- set class to show small size image-->
<td class = "small"><img src="city/img23.jpg" alt=""></td>
<td class = "small"><img src="city/img24.jpg" alt=""></td>
<td class = "small"><img src="city/img25.jpg" alt=""></td>
</tr>
</table>
</body>
I have a database containing movies Name, their description and their cover picture. The cover picture field type is as blob and the problem is that I can't retrieve it from the database. I want to display the movie name along their cover picture beside them... How to do it.. Here is my code..
<?php
include ("php/connection.php");
$ID = $_GET['id'];
$listmovies = "SELECT * FROM movies where Genres LIKE '%$ID%'";
$result = mysql_query($listmovies);
while ( $row = mysql_fetch_assoc($result) ) {
?>
<table border="1" width="100%">
<tr>
<td rowspan="2" width="90" height="120">
<?php
// set the header for the image
header("Content-type: image/jpeg");
echo $row['Image'];
?> </td>
<td width="200" height="10">
<?php
echo $row['Title'];
?></td>
</tr>
<tr>
<td width="200" height="110">More Detail</td>
</tr>
<?php } ?> </table>
I just want to display The Imgaes beside the title of the movie?
Yes it won't display because any output above header would always generate error ... you need to have a different page to output your image or include it has base64 image
Remove
header("Content-type: image/jpeg");
echo $row['Image'];
And add this :
printf("<img src=\"data:image/jpeg;base64,%s\" />",base64_encode($row['Image']));
^--- Note this is only for jpeg images
I suggest something like that:
Make a new php file called for example image.php; That file will replace physical image file.
In that file you put the code from your post plus some logic to get image data from database;
In parent template(php file maybe) you put code for image:
<img src="image.php?id_movie=<?php echo $id_movie; ?>" width ="200" height="200" /> More Detail
In image.php i suggest to be careful at spaces outside php tags (at the beniging and at the end).
Also to image.php you need to give id of the movie to know what image to load from database.
<?php
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?php print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>° C,
<?php echo $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<?php foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?php echo $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?php echo round(conver_f_c($forecast->low['data'])); ?>° C - <?php echo round(conver_f_c($forecast->high['data'])); ?>° C,
<?php echo $forecast->condition['data'] ?>
</span>
</div>
<?php endforeach ?>
</body>
</html>
<?php
function conver_f_c($F){
return $C = ($F − 32) * 5/9;
}
I want Out somthing like this manner of the horizontal ,
Even i tried UL LI WITH display inline but it goes failed,
Tell me some good suggestion for my probme,
I want exactly like horizontal, expecting exactly like screen shot ,
Tell me How to render using php
Thanks
alt text http://img163.imageshack.us/img163/7518/weatherhori.jpg
Above snippet present display out verticly , i want o change that verticle to horizonatal ,
somthing like this screen shot
<table>...</table>
Update
From your latest comment so far:
i know how to fetch array and display
it, but i dont know to fetch and
display in the verticl manner that is
the stuck up
I feel this is going to be a stupid answer but it appears to be what you don't understand...
The web is based in a markup language called HTML. This language has tags (delimited by angle-brackets) that allow you to define the structure of a document. On top of this, you have another language called CSS. This other lang allow you to define how HTML is going to be displayed on screen.
You may argue that you already have a web page and you've written it with the PHP language instead of the two other langs I've mentioned. That's not enterely true: you code in PHP, sure, but you use PHP to generate HTML. And it's HTML what finally reaches the browser (Firefox, Explorer...). PHP is executed in the web server, not in the browser. The browser can only see whatever HTML you've generated.
To sum up: you have to forget about PHP, Google and the whole weather thingy. You first need to write a static HTML document and style it with CSS. Once you've done with it, you can finally replace the parts of the information that are dynamic with values taken from your PHP variables.
And since you seem to need a table to display tabular data, the appropriate HTML tag is <table>:
<table>
<tr>
<th>Web</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
<td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
<td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
</tr>
<tr>
<td>26ºC</td>
<td>26ºC</td>
<td>22ºC</td>
<td>25ºC</td>
</tr>
<table>
I suggest you find some tutorials about basic HTML and CSS. They'll be of invaluable help.
This is what's done by Google :
http://jsfiddle.net/bW8NA/1