Jump to content

Recommended Posts

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!!

Link to comment
https://forums.phpfreaks.com/topic/276687-images-in-mysql/
Share on other sites

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);



?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/276687-images-in-mysql/#findComment-1423552
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/276687-images-in-mysql/#findComment-1423577
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.