Jump to content

Fetch Random Images From Database


varun7952

Recommended Posts

i m tryin to fetch random images from database on external page it fetch id user id name but not image and i only want to fetch images(thumb) please guys help me

 

 

here is my code

 

<?php

$connect= mysql_connect('localhost','root',' ');
if($connect) {
mysql_select_db ('wall_paper',$connect);

$query= ("SELECT * FROM wallpapers ORDER BY Rand() LIMIT 5");
$result= mysql_query($query);

echo "<table border='1'>";
while ($row=mysql_fetch_array($result, MYSQL_NUM)){
echo "<tr><td>$row[0] </td><td>$row[1]</td><td>$row[2]</td></tr>";
}
echo "</table>";
}
else{
echo "cant connet to the database";
}
?>

 

i attached image of my database from where i m fetching data

post-126383-0-38724500-1349942434_thumb.jpg

Link to comment
Share on other sites

Where is the image being stored? On a file? How do you know the path / location to the image?

 

That code you have there, even the database image, does not hint to any such information. We will need to know that to assist you.

Link to comment
Share on other sites

Actually, hashing the image's data and then renaming the file is a pretty good idea; No filename collisions, and you can test quite easily if you have the picture already (or not). Of course, it's pointless unless you rename the file.

 

Hashes are not guaranteed to be unique, so there is still the potential for a name collision. And since there may be collisions with different data, you cannot be sure that a duplicate hash means you have received a duplicate image. All in all, hashing the image data and using it as the filename is not such a good idea. Also, consider that a user may add (or remove) tag data to (or from) an image, and it would produce a different hash even though the visual image is the same.

 

Hashes are designed to "prove" that the data has been changed. You could store the hash of a (image) file in the database; then, before displaying the image, run a hash on the file and compare the two hashes. If they are different, then someone changed the file; if they are the same, then the file has probably not been changed. Since hashes are not guaranteed to be unique, it is conceivable that the file could be changed in such a way as to cause the hash to be the same. Using a salt helps prevent someone from purposefully making such a change; since without the salt they don't know what hash value they are working toward. And the odds of it happening accidentally are very slim.

Link to comment
Share on other sites

  • 3 weeks later...
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.