|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| 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! |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
|
|||
|
__________________
if you're reading this, I'm bored |
|
|||
|
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 |
|
|||
|
Quote:
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. |
|
||||
|
Quote:
Graphic Video, Hosting image gallerys etc.. PHP Links SQL Links |
|
|||
|
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 |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |