Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
get random image from DB... modfiy script help. :D
Old 09-14-2007, 04:12 PM get random image from DB... modfiy script help. :D
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hello,

Im currently doing a random iamge script/system

Ok, the guy is currently using this script:
PHP Code:
<?php
/*
By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
http://photomatt.net/scripts/randomimage
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder 'upload/';
// Space seperated list of extensions, you probably won't have to change this.
$exts 'jpg jpeg png gif';
$files = array(); $i = -1// Initialize some variables
if ('' == $folder$folder './';
$handle opendir($folder);
$exts explode(' '$exts);
while (
false !== ($file readdir($handle))) {
foreach(
$exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i'$file$test)) { // faster than ereg, case insensitive
$files[] = $file// it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand mt_rand(0$i); // $i was incremented as we went along
header('Location: '.$folder.$files[$rand]); // Voila!
?>
and has <img src="randomscript.php" />

this script selects a random image form the folder and shows..

im now making the whole uplaod and a moderation system for this
and im planning to have a simple db table with

ID | imagefile | status

on upload it auto inserts a entry with the filename.ext and the status as moderate or soemthing...

then have a thing so once image has been checked ut updates status...

anyway... ]

so how can i have the above script select a random image which has a status of live (or whatever i choose) and also possibly add a check that it exists.

i mean i can do the sql query and if exists check its just im not sure how to go about getting the result of these files and then haveing it select on at random???

I hope you get what i mean here! because i jsut confused myself.

Anwyay thanks
Tp for good answers!

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 09-14-2007, 05:24 PM Re: get random image from DB... modfiy script help. :D
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Okay i have all the dba nd everything done now, so i just need to know the best way to get all the image_name's (which is image.jpg format) and have the scrpt randomly slect one

HEELP ANYONE!!!
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-14-2007, 07:17 PM Re: get random image from DB... modfiy script help. :D
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Anyone...

how do i go from

$image_query = mysql_query("SELECT image_name FROM images WHERE status='approved'") or die("Error getting iamge info from DB");

to the script randomly selecting one of the images which fit into the status approved cat?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-14-2007, 11:16 PM Re: get random image from DB... modfiy script help. :D
Experienced Talker

Posts: 44
Name: Kuldeep Sahi
Trades: 0
Try this:

Code:
 SELECT
    image_name
FROM 
    images
WHERE 
    status='approved'
ORDER by RAND()
LIMIT 1;
__________________

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
Kuldeep2195 is offline
Reply With Quote
View Public Profile Visit Kuldeep2195's homepage!
 
Old 09-15-2007, 05:30 AM Re: get random image from DB... modfiy script help. :D
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thanks alot, works a treat!

given you TP ! XD

now all i have to do is knock upa aadmin bit and im DONE!!
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE

Last edited by dansgalaxy; 09-15-2007 at 05:45 AM..
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-15-2007, 10:27 PM Re: get random image from DB... modfiy script help. :D
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
Upload the files using a form then have your form store the name of the file in the database and upload the file
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 09-16-2007, 08:13 AM Re: get random image from DB... modfiy script help. :D
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Please read the thread John... it makes you look very stupid.

Firstly i have explained i have all the upload done and it adds it to the database my problem was i didnt know how to select a random entry from the db...
Kuldeep2195 gave me a answer, i gave him TP. i praised him thanked him and said it worked...

So not only have you not read the thread and given a answer which doesnt fit the question you are also replying to a thread which is done and dusted.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-16-2007, 12:54 PM Re: get random image from DB... modfiy script help. :D
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
Not what I ment

I meant make a form that will do it for uploading or create an array of the file names then add them to a DB
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 09-16-2007, 01:31 PM Re: get random image from DB... modfiy script help. :D
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
To everyone ecept John:

Am i missing something? seriously? or is he still answering a question i wasnt asking??? :P
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-16-2007, 01:43 PM Re: get random image from DB... modfiy script help. :D
joder's Avatar
Flipotron

Posts: 6,442
Name: James
Location: In the ocean.
Trades: 0
I'm lost trying to figure it out
joder is offline
Reply With Quote
View Public Profile
 
Old 09-16-2007, 01:55 PM Re: get random image from DB... modfiy script help. :D
Super Talker

Posts: 130
Trades: 0
nope, you're not missing anything dansgalaxy. John is really answering a question that you're not asking. You would think if he had even read the title of the thread he'd understand what it was about.
__________________
flann

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Old 09-16-2007, 02:22 PM Re: get random image from DB... modfiy script help. :D
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thanks.. im glad its not just me, i swear i was this close ii <- to taking TP off him i was like O_O you have to be kiddin' me.. Lol
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to get random image from DB... modfiy script help. :D
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33618 seconds with 12 queries