Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-16-2006, 05:07 AM
WebProWorld Pro
 

Join Date: Jul 2003
Location: Canada
Posts: 265
ackerley1 RepRank 0
Default Another PHP/MySQL Image question

I am working on a site that makes use of pre-made image gallery program and stores the images in a DB. What I want to do is randomly pull an image from the DB, scale it to a certain width, and display it within a block on each page. If possible, have it rotate through after x seconds without waiting for the user to navigate?

Problem is I know very little of DB queries and displaying that information.

Any suggestions?
__________________
Rob
Reply With Quote
  #2 (permalink)  
Old 09-18-2006, 05:56 PM
WebProWorld Member
 

Join Date: Jun 2006
Location: islip, ny
Posts: 42
philscanlan RepRank 0
Default

here's a start:

php.net/gd
__________________
if you're reading this, I'm bored
Reply With Quote
  #3 (permalink)  
Old 09-18-2006, 06:01 PM
WebProWorld New Member
 

Join Date: Apr 2004
Location: Chantilly, Virginia
Posts: 18
fr3nch13 RepRank 0
Default

in your query you can do this:

SELECT * FROM `images` ORDER BY RAND();

that will pull a random entry in the table.

With a where statement:

SELECT * FROM `images` WHERE `active`='Y' ORDER BY RAND();
__________________
Brian French
Technical Director
ImageWorks Studio
bfrench@imageworksstudio.com
Web Design Virginia
Web Developer Virginia
Reply With Quote
  #4 (permalink)  
Old 09-18-2006, 06:05 PM
WebProWorld Veteran
 

Join Date: Apr 2004
Posts: 304
imvain2 RepRank 0
Default

Quote:
Originally Posted by fr3nch13
in your query you can do this:

SELECT * FROM `images` ORDER BY RAND();

that will pull a random entry in the table.

With a where statement:

SELECT * FROM `images` WHERE `active`='Y' ORDER BY RAND();
Actually that isn't correct, those statements will pull back every image in the database but sort them in a random order. You can use those statements and not loop through the results but then you are just wasting system resources for no reason.

select image_url from images where active = 1 order by rand() limit 5;

this select statement will pull back the top 5 randomly selected images. This statement would work well with a slideshow from DynamicDrive.com.
Reply With Quote
  #5 (permalink)  
Old 09-19-2006, 05:17 AM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: United Kingdom
Posts: 1,858
TrafficProducer RepRank 1
Default Scale it to a certain width

Quote:
Scale it to a certain width
ImageMagickTM is a robust collection of tools and libraries to read, write, and manipulate an image in many image formats. (This should help you, it's more powerful the GD, so far as i Know, and works with PHP, PERL etc...

Graphic Video, Hosting image gallerys etc..

PHP Links SQL Links
__________________
Videos to Watch and Video Publishing
Affiliate Program! Our Affiliate Program Pays 50.00% Business Support
Reply With Quote
  #6 (permalink)  
Old 09-23-2006, 09:54 PM
DrTandem1's Avatar
WebProWorld 1,000+ Club
 

Join Date: Oct 2003
Location: Encinitas, CA
Posts: 1,908
DrTandem1 RepRank 2
Default

You don't need a data base for this. A simple directory of images with the script also in the directory. The image on the HTML page is called from the script in that directory.

If you are going to rotate them anyway, just do the same with a PHP slideshow script. The only drawback, to keep it simple, is that the images must all me the same width and height. This is overcome as an issue by finding the largest image, and then setting a background that will contain it. The subsequent, smaller images are simply pasted as a new layer on this background and you then have another image of the same size as the first.

Again, keep it simple, you don't need a database. You can also add hyper links to the images.
__________________
DrTandem's San Diego Web Page Design, drtandem.com
Reply With Quote
  #7 (permalink)  
Old 10-03-2006, 05:12 AM
WebProWorld Pro
 

Join Date: Jul 2003
Location: Canada
Posts: 265
ackerley1 RepRank 0
Default

Thanks for the help... next issue...

Okay, so I have it pulling from the DB using a sql_conn.php file and I have set up the following function (copied from another example I found):

function get_rand_img()
{
// Make the Query
$query = "SELECT image_url FROM images WHERE active = 1 ORDER BY rand() limit 1";
// Run the query
$result = @mysql_query ($query);
// How many are there?
$num = mysql_num_rows($result);
// If it ran okay, display records
if ($num > 0)
{
echo '<table width="100%" border="1" cellspacing="5" cellpadding="5"><tr><td>';
while ($img = mysql_fetch_array($result))
{
echo '[img]gall/images/'.$img.'[/img]';
}
echo '</td></tr></table>';

}
}

However it is still not showing the image correctly... when I view source from browser... the img take reads like this:
[img]gall/images/Array[/img]

Like I said, very limited knowledge with DB queries, so I am sure this is a simple error.

Please help.

Rob
__________________
Rob
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0