stephflix Posted April 8, 2013 Share Posted April 8, 2013 I was wondering if there is a image format code is get images from a database to show up. For example I use: <td>' . number_format($row['Population']) . '</td> the number_format to fix the population to show up the way I want. Is there an image format? Or what do I do? Right now it's showing up as a long string of text. <td>' . $row['Picture'] . '</td> Thanks in Advance!! Quote Link to comment https://forums.phpfreaks.com/topic/276687-images-in-mysql/ Share on other sites More sharing options...
stephflix Posted April 8, 2013 Author Share Posted April 8, 2013 Maybe seeing the entire code might help.... <?php // connect to database require_once('includes/mysqli_connect_northwind.php'); ?> <?php //get our parameters // condition ? true value : false value $sort = isset($_GET['sort']) ? $_GET['sort'] : "CategoryName"; $dir = isset($_GET['dir']) ? $_GET['dir'] : "ASC"; // our query to select categories $query = "SELECT * FROM categories ORDER BY $sort $dir"; // execute our query $result = @mysqli_query($dbc, $query) or die('Error in query: ' . mysqli_error($dbc)); // sort directions $cat_dir = ($sort == "CategoryName" and $dir == "ASC") ? "DESC" : "ASC"; $desc_dir = ($sort == "Description" and $dir == "ASC") ? "DESC" : "ASC"; $pic_dir = ($sort == "Picture" and $dir == "ASC") ? "DESC" : "ASC"; // loop through results echo '<table> <thead> <tr> <td><a href="?sort=CategoryName&dir='.$cat_dir.'">Category Name</a></td> <td><a href="?sort=Description&dir='.$desc_dir.'">Description</a></td> <td><a href="?sort=Picture&dir='.$pic_dir.'">Picture</a></td> </tr> </thead> <tbody>'; // loop through the results while( $row = mysqli_fetch_array($result) ){ // $row represents the current record in the database //echo '<pre>'; //print_r($row); //echo '</pre>'; // $row['ColumnName'] echo '<tr> <td><a href="products2.php?CategoryName=' . $row['CategoryName'] . '"> ' . $row['CategoryName'] . ' </a></td> <td>' . $row['Description'] . '</td> <td>' . $row['Picture'] . '</td> </tr>'; } echo '</tbody> </table>'; // close connection to database mysqli_close($dbc); ?> Quote Link to comment https://forums.phpfreaks.com/topic/276687-images-in-mysql/#findComment-1423552 Share on other sites More sharing options...
jazzman1 Posted April 8, 2013 Share Posted April 8, 2013 If you want to store a image to database you need set the field "Picture", as a BLOB type. Quote Link to comment https://forums.phpfreaks.com/topic/276687-images-in-mysql/#findComment-1423571 Share on other sites More sharing options...
stephflix Posted April 8, 2013 Author Share Posted April 8, 2013 I'm not trying to store an image to a database. I'm trying to take the image from the database and put in on my website through PHP. Quote Link to comment https://forums.phpfreaks.com/topic/276687-images-in-mysql/#findComment-1423576 Share on other sites More sharing options...
gizmola Posted April 8, 2013 Share Posted April 8, 2013 This is basic html. You can not just embed a picture in an html document. Images have to be sourced independently using the: <img src="path_to_image"> This is one of several reasons that people don't typically store image data in a database table. However, given the current design it appears you have, what you will have to do instead is write a seperate script that will lookup the row that contains the image data so that in your img tag you can provide the path in a manner similar to this: <img src="getimage.php?id=<?php echo $row['id'] ?>"> the get image.php script would lookup the row by id, set the mime type to the one appropriate for the type of image that was stored (jpg, gif, png) and return the image data. Quote Link to comment https://forums.phpfreaks.com/topic/276687-images-in-mysql/#findComment-1423577 Share on other sites More sharing options...
Barand Posted April 9, 2013 Share Posted April 9, 2013 I'm not trying to store an image to a database With respect to the image, what precisely are you storing in the database? Quote Link to comment https://forums.phpfreaks.com/topic/276687-images-in-mysql/#findComment-1423606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.