0o0o0 Posted October 30, 2012 Share Posted October 30, 2012 (edited) $files = glob("./images/$code/*.*"); for ($i=0; $i<count($files); $i++) { $num = $files[$i]; Basically Im creating a k i j j i ji like site for a friend.. the second page works fine and shows all the photos.. whether its 1 or 20.. the first page is where I need to ONLY grab one photo file per listing. How do I modify this code to grab one photo ( either first in the folders or random any in the folders) The names are unknown to me to just simply code it by photo names. so the code above work would perfectly if I can only get one .. I tried $i=0; to $i=1; but that only takes a photo away. Im assuming its changing the count to... ? ... help me out thanks! Edited October 30, 2012 by 0o0o0 Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/ Share on other sites More sharing options...
Muddy_Funster Posted October 30, 2012 Share Posted October 30, 2012 you could try chan ging from a for loop to a strait rand() $i = rand(0, count($files)); $num = $files[$i]; You may need to do the count() before the rand() and asign it to it's own variable, rand() is not a function I use often, so I'm not sure what it takes as valid options. Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388665 Share on other sites More sharing options...
0o0o0 Posted October 30, 2012 Author Share Posted October 30, 2012 This posts singles!!.. lol cept randomly.. like picture blank - description info picture - description info picture - description info picture - description info blank- description info thanks tho! Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388668 Share on other sites More sharing options...
Muddy_Funster Posted October 30, 2012 Share Posted October 30, 2012 ... How do I modify this code to grab one photo ( either first in the folders or random any in the folders) ... This posts singles!!.. lol cept randomly.. like ... So is that what you wanted? Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388673 Share on other sites More sharing options...
0o0o0 Posted October 30, 2012 Author Share Posted October 30, 2012 what you sent works.. but for some reason.. its like this.. My first page is the LISTINGS page.. photo - Then my description text is here photo - Then my description text is here photo - Then my description text is here BLANK - Then my description text is here photo - Then my description text is here BLANK - Then my description text is here photo - Then my description text is here BLANK - Then my description text is here photo - Then my description text is here photo - Then my description text is here photo - Then my description text is here BLANK - Then my description text is here but even the ones that show up blank have photos in the folders. Odd I know but some photos arnt showing up with your code. So its half right tho! which is good single photos are coming up for each description line. cept a few are skipping.. wierd huh. Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388677 Share on other sites More sharing options...
Muddy_Funster Posted October 30, 2012 Share Posted October 30, 2012 it's probably a range thing. count() starts at 1 not 0, so the range in the rand() will be larger than the $file array. change it to count($files)-1 and see if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388678 Share on other sites More sharing options...
0o0o0 Posted October 30, 2012 Author Share Posted October 30, 2012 THANKS BFF!!! lol.. perfect!. Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388681 Share on other sites More sharing options...
Muddy_Funster Posted October 30, 2012 Share Posted October 30, 2012 BFF...? Anyway, your welcome - glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388683 Share on other sites More sharing options...
0o0o0 Posted October 30, 2012 Author Share Posted October 30, 2012 haha.. BEST FRIEND FOREVER! im kiddin around. Thanks tho Quote Link to comment https://forums.phpfreaks.com/topic/270067-help-modifying-code-to-grab-only-one-file-from-folder-instead-of-all/#findComment-1388685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.