Using PHP to display semi-random images?

Hello,
I'm looking for help using PHP and MySQL to generate semi-random images on my web site. Here's what I'm trying to do: I have 60 images, but I only want to display 16 at a time (for examlpe http://artisdead.net/antelopegardens.php).
The way I imagine this is, the design has 16 image placeholders. I want Placeholder 1 (the first image) to randomally pull record ID 1, 2, or 3 from the SQL database, while Placeholder 2 pulls record ID 4-6, etc. It's important that one of the first 3 images displays first, while one of the second 3 images displays next, etc.
I've found various ways to randomize all the images, but I'm not understanding how to constrain the randomization the way I'm looking to. Any help would be greatly appreciated. Thanks in advance.

Alamo_Melt wrote:
 The way I imagine this is, the design has 16 image placeholders. I want Placeholder 1 (the first image) to randomally pull record ID 1, 2, or 3 from the SQL database, while Placeholder 2 pulls record ID 4-6, etc. It's important that one of the first 3 images displays first, while one of the second 3 images displays next, etc.
Before offering a possible solution, I should point out that your plan has a minor flaw. If you display only 16 images, and want the random choice to come from incremental sets of three, the maximum number you can have in your set is 48. The final 12 images will never be selected. For 60 images, you need 20 placeholders. The alternative is to have a total set of 64 images, and make the random choice come from incremental sets of four images.
With that caveat, here's how I would do it. The primary keys of your records might not be consecutive, particularly if records are deleted and new ones added, so it might be a good idea to have a separate column with consecutive numbers from 1 to the the maximum. To select random numbers from incremental groups of three, use the following:
$id = array();
$min = 1;
$max = 3;
for ($i = 0; $i < 16; $i++) {
  // generate random number from current set
  $id[$i] = mt_rand($min, $max);
  // increment the minimum and maximum numbers for the next set
  $min += 3;
  $max += 3;
// join the selected values as a comma-separated string
$vals = implode(',', $id);
$sql = "SELECT image FROM images WHERE id IN ($vals)";
// excecute the SQL query

Similar Messages

  • Using PHP to display OID jpegPhoto attribute

    Has anyone been able to display the OID jpegPhoto attribute using PHP?
    I'm running OAS 10g R2 with PHP 4.3.9
    I've activated the PHP extension modules gd2lib and exif to manipulate images.
    I can also retrieve and display all OID attributes using PHP, except for the jpegPhoto attribute which looks like a small binary string.
    Any help would be appreciated.
    Thanks.

    create a procedure with this code
    OWA_UTIL.mime_header (l_mime, FALSE);
    OWA_UTIL.http_header_close;
    WPG_DOCLOAD.download_file (l_lob);
    where l_lob is your BLOB field and l_mime is the mime type of the photo.
    and then in your page just write
    <img src=/portal/pls/portal/my_schema/my_plsql_proc?param1=value1>

  • How use PHP to read image files from a folder and display them in Flex 3 tilelist.

    Hello. I need help on displaying images from a folder dynamically using PHP and display it on FLEX 3 TileList. Im currently able to read the image files from the folder but i don't know how to display them in the TileList. This is my current code
    PHP :
    PHP Code:
    <?php
    //Open images directory
    $imglist = '';
    $dir = dir("C:\Documents and Settings\april09mpsip\My Documents\Flex Builder 3\PHPTEST\src\Assets\images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "filename: " . $file . "\n";
    $dir->close();
    ?>
    FLEX 3 :
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="pic.send();">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.rpc.events.ResultEvent;
    public var image:Object;
    private function resultHandler(event:ResultEvent):void
    image = (event.result);
    ta1.text = String(event.result);
    private function faultHandler(event:FaultEvent):void
    ta1.text = "Fault Response from HTTPService call:\n ";
    ]]>
    </mx:Script>
    <mx:TileList x="31" y="22" initialize="init();" dataProvider = "{image}" width="630" height="149"/>
    <mx:String id="phpPicture">http://localhost/php/Picture.php</mx:String>
    <mx:HTTPService id="pic" url="{phpPicture}" method="POST"
    result="{resultHandler(event)}" fault="{faultHandler(event)}"/>
    <mx:TextArea x="136" y="325" width="182" height="221" id="ta1" editable="false"/>
    <mx:Label x="136" y="297" text="List of files in the folder" width="182" height="20" fontWeight="bold" fontSize="13"/>
    </mx:Application>
    Thanks. Need help as soon as possbile. URGENT.

    i have made some changes, in the php part too, and following is the resulting code( i tried it, and found that it works.):
    PHP Code:
    <?php
    echo '<?xml version="1.0" encoding="utf-8"?>';
    ?>
    <root>
    <images>
    <?php
    //Open images directory
    $dir = dir("images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "<image>" . $file . "</image>"; // i expect you to use the relative path in $dir, not C:\..........
    //$dir->close();
    ?>
    </images>
    </root>
    Flex Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="callPHP();">
    <mx:Script>
    <![CDATA[
    import mx.rpc.http.HTTPService;
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    private var arr:ArrayCollection = new ArrayCollection();
    private function callPHP():void
    var hs:HTTPService = new HTTPService();
    hs.url = 'Picture.php';
    hs.addEventListener( ResultEvent.RESULT, resultHandler );
    hs.addEventListener( FaultEvent.FAULT, faultHandler )
    hs.send();
    private function resultHandler( event:ResultEvent ):void
    arr = event.result.root.images.image as ArrayCollection;
    private function faultHandler( event:FaultEvent ):void
    Alert.show( "Fault Response from HTTPService call:\n " );
    ]]>
    </mx:Script>
    <mx:TileList id="tilelist"
    dataProvider="{arr}">
    <mx:itemRenderer>
    <mx:Component>
    <mx:Image source="images/{data}" />
    </mx:Component>
    </mx:itemRenderer>
    </mx:TileList>
    </mx:Application>

  • Using Flex/PHP to Display MYSQL data and Images

    Does anyone have any good examples of using Flex 3 in conjunction with PHP to display data and images from a mysql database? I've searched a lot and it seems hard to find this combination. I have manged to create a login system using this which allows users to login via usernames and passwords that are stored in my mysql database (Grizzz helped me out a lot with this).
    But I now want to create a product selection in the site with the categories down the left hand side and the products related to these categories displayed in the other panel once each of these products are clicked. The guy I'm making it for wants to be able to add and delete categories as well as add and delete products so obviously it needs to be done using php and mysql. I'm looking for something similar to the way the online shop is laid out in the following example:-
    https://www.whitestonecheese.co.nz/Radshop/bin/Whitestone.html
    Thanks for any suggestions.

    To solve this problem I had to use labelFunction.  The working line was this:
    <mx:DataGridColumn headerText="Description" labelFunction="dataGrid_labelFunc"  dataField="messageDetail"/>
    The function looks like this:
    private function dataGrid_labelFunc(item:XML, col:DataGridColumn):String {
         var qN:QName = new QName(vm, col.dataField);
         return item[qN].text();

  • PHP random image

    Hello everyone,
    Im trying to use (for the first time) random images generated
    by PHP. I
    installed a Technorama extension and then followed thru the
    steps to place a
    random image in the page, but there is nothing there when I
    browse the page.
    Please forgive my ignorance, but I have never done any php
    stuff before.
    And yes, the files are uploaded to my server. (which does
    have php enabled).
    The practice page I am using is
    www.fionahayward.com/interiordesign/practice.php
    I have the effect working with javascript on this page
    www.fionahayward.com/interiordesign but am trying to use php
    incase people
    have javascript turned off.
    Maybe its something to do with how Ive set up Server
    Behaviours or something
    (only guessing)
    Thanks for listening
    Fiona

    1) create a php file named rotate.php in the folder where the
    images are.
    2) paste this code (between the [code ] and [/code]
    markers... into that file and save it.
    [code]
    <?php
    $folder = '.';
    $extList = array();
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';
    // --------------------- END CONFIGURATION
    $img = null;
    if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
    if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
    isset( $extList[ strtolower( $imageInfo['extension'] ) ] )
    file_exists( $folder.$imageInfo['basename'] )
    $img = $folder.$imageInfo['basename'];
    } else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
    $file_info = pathinfo($file);
    if (
    isset( $extList[ strtolower( $file_info['extension'] ) ] )
    $fileList[] = $file;
    closedir($handle);
    if (count($fileList) > 0) {
    $imageNumber = time() % count($fileList);
    $img = $folder.$fileList[$imageNumber];
    if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[
    $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
    } else {
    if ( function_exists('imagecreate') ) {
    header ("Content-type: image/png");
    $im = @imagecreate (100, 100)
    or die ("Cannot initialize new GD image stream");
    $background_color = imagecolorallocate ($im, 255, 255, 255);
    $text_color = imagecolorallocate ($im, 0,0,0);
    imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
    imagepng ($im);
    imagedestroy($im);
    ?>
    [/code]
    4) in whichever file you want the random images to appear,
    reference the image so:
    src="path/to/that/image/folder/rotate.php"
    I tend to use root-relative pathing, but that part is up to
    you.
    NOTE: I've found that random image references are quirky in
    IE browsers - they seem to want the image width and height to
    display images that are dynamically selected... I've used this
    script to display images that are all the same size and groups that
    aren't. When the image size is unknown, I use width:100%
    height:100% in my css)
    email me if you have any issues with using the script. I use
    it a lot with WordPress sites, but it isn't a WP only solution.
    syncbox AT gmail DOT com (do the obvious)
    HTH

  • Display random image

    Hey all. Creating my first form in LiveCycle. Haven't a clue as to what I'm doing... maybe someone can help.
    I don't know javascript, so I usually just use trial and error until I figure it out... but I just can't get this to work.
    I have 20 images on my form (named ImageField#hg), invisible. I want to display a random image when I click a button.
    Here is the code I thought would work.... it's placed in the Click script section on a button.
    var one = "ImageField";
    var two = "hg";
    var rannumb = Math.floor(Math.random() * 19+1);
    var showg = one + rannumb + two;
    showg.presence = "visible";
    If I test the output in a text box, I get ImageField#hg (# being the random number), so why doesn't it actually execute the .presence action?
    Thank you.
    -James

    I've been trying to change my thinking on this and came up with different code, but it still won't work properly.
    This frist script actually does change the images to visible... however, it's processing the variable for some reason and both images become visible on click. I didn't know variable would do anything unless called.
    var one = ImageField1hg.presence = "visible";
    var two = ImageField2hg.presence = "visible";
    var rannumb = Math.floor(Math.random() * 19+1);
    var newnumb = WordNum(rannumb);
    testing.rawValue = newnumb; // test field to see output doesn't show anything
    newnumb;
    So I changed the script to the following and it does nothing.
    var one = ImageField1hg.presence;
    var two = ImageField2hg.presence;
    var rannumb = Math.floor(Math.random() * 19+1);
    var newnumb = WordNum(rannumb);
    testing.rawValue = newnumb; // test field to see output doesn't show anything
    newnumb = "visible";
    Back to the drawing board...

  • Kaos weaver random image code does not validate with w3c

    Hi
    I have done a quick test validation on a site I am working
    on, I have used Kaos Weaver's Advanced Random Image extension .
    When Validating this comes up with about 60 errors, the ones I have
    done I have corrected but not uploaded yet. Unfortunately I am not
    skilled in java to go about correcting the kaos weaver errors.
    Link to w3c:
    http://validator.w3.org/check?uri=www.blanc-wall.co.uk%2FUp2Press%2520Website%2Findex.htm
    Any help would me much appreciated guys
    Andy

    Mick White wrote:
    > andy_forbes wrote:
    >
    >> Hi I have done a quick test validation on a site I
    am working on, I
    >> have used Kaos Weaver's Advanced Random Image
    extension . When
    >> Validating this comes up with about 60 errors, the
    ones I have done I
    >> have corrected but not uploaded yet. Unfortunately I
    am not skilled in
    >> java to go about correcting the kaos weaver errors.
    >>
    >> Link to w3c:
    >>
    http://validator.w3.org/check?uri=www.blanc-wall.co.uk%2FUp2Press%2520Website%2F
    >>
    >> index.htm
    >>
    >> Any help would me much appreciated guys
    >>
    >> Andy
    >>
    > Bad link
    > Mick
    Oops, good link, errors are basic, Every image needs an "alt"
    attribute,
    and "&" needs to be encoded as "&amp;".
    Mick

  • Displaying a stereoscopic image for shutter glasses displays

    I am very new to flex, I am trying to decide which toolset will be optimal for me.
    Is it possible to create an application using flex that displays a stereoscopic image, which can be viewed using nVidia 3D Vision glasses? If yes, can you give me some starting points?
    My application will receive generated stereo images in real time over the network and should display them. I have complete control over the generation of the images, know how stereo images work, and know to write such an application in C++/DirectX.
    Youtube's flash player recently got 3D Vision stereoscopic movie support, so I assume this should be possible.
    Thanks for any help

    Hey ronfya
    Did you ever get any feedback on this? I haven't read the Technicolor link yet.  I was just trying to figure out why my stuff comes out darker on Vimeo. Could this be because FCPX is displaying it to brightly?
    A.T.

  • How to display image in database using php

    i've try search all hope that you all can give me some guidance how to display data that is in image or BLOB using PHP. just a query and php code that will make display of the image. hope that you all show me the example or give me reference that i need to solve my problem.

    Hi,
    Have a check on these Google results, you might find something there...
    http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&q=%22display%20image%22%2Boracle%20%2Bphp

  • PHP Random Image extension

    I am trying to use the PHP random image generator but I don't
    know where to specify the size I want all the pictures to come up
    in the code. I created a "php" test page and inserted said code
    where I want the images to display but they are too large and throw
    the entire page off. Is there a way to tell it that all pictures
    should be called up at 240(width) x 350(height)? Any help would be
    greatly appreciated. The reason I am doing this is because there
    are about 200 images (of students) in this folder and coding each
    picture seperately is too time consuming.
    Regards,
    RM (using DW MX2004)

    Disregard....I figured it out. As it turns out the best
    solution would be to have your original pictures saved with the
    desired dimensions. I was able to point the PHP to a directory that
    contained pictures with said dimensions and it worked like a charm.
    regards.

  • Using PHP to generate images in alternate colors

    I have a PNG image of a black silhouette graphic with
    softened edges against a transparent background.
    Can I use PHP to generate this image in alternate colors
    (allowing the black graphic to be displayed in a color other than
    black)?

    AngryCloud posted in macromedia.dreamweaver:
    > I have a PNG image of a black silhouette graphic with
    softened
    > edges against a transparent background.
    >
    > Can I use PHP to generate this image in alternate colors
    > (allowing the black graphic to be displayed in a color
    other than
    > black)?
    I have no experience with this, but I was just poking around
    in the GD
    references and found a comment on imagefill() that might
    help:
    http://us.php.net/manual/en/function.imagefill.php
    Comment:
    http://us.php.net/manual/en/function.imagefill.php#81873
    Or you may need to work with some of the other alpha
    functions.
    Mark A. Boyd
    Keep-On-Learnin' :)

  • Using a IP191 monitor, have random horizontal streaks on display - have no problem with other browsers; also no problem with FF on other family PC's

    Using a IP191 monitor, have random horizontal streaks on display - have no problem with other browsers; also no problem with FF on other family PC's.
    These "streaks" appear to be area of too high frequency scanning; they can be cleared by scrolling up and/or down.

    hello, maybe that's an issue with hardware acceleration - please try [[Upgrade your graphics drivers to use hardware acceleration and WebGL|updating your graphics driver]], or in case this doesn't solve the issue or there is no new version available at the moment, disable hardware acceleration in the firefox ''menu [[Image:New Fx Menu]] > options > advanced > general''.

  • Inserting image in a table using php +zend

    Hy!
    The table is
    (products(picture_p blob,prod_id number)) when i try to insert the pictureusing a similar code with this from oracle .com:
    // Insert the BLOB from PHP's tempory upload area
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
    $stmt = oci_parse($conn, 'INSERT INTO BTAB (BLOBID, BLOBDATA) '
    .'VALUES(:MYBLOBID, EMPTY_BLOB()) RETURNING BLOBDATA INTO :BLOBDATA');
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_bind_by_name($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
    oci_execute($stmt, OCI_DEFAULT);
    // The function $lob->savefile(...) reads from the uploaded file.
    // If the data was already in a PHP variable $myv, the
    // $lob->save($myv) function could be used instead.
    if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
    oci_commit($conn);
    else {
    echo "Couldn't upload Blob\n";
    $lob->free();
    oci_free_statement($stmt);
    // Now query the uploaded BLOB and display it
    $query = 'SELECT BLOBDATA FROM BTAB WHERE BLOBID = :MYBLOBID';
    $stmt = oci_parse ($conn, $query);
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_execute($stmt, OCI_DEFAULT);
    $arr = oci_fetch_assoc($stmt);
    $result = $arr['BLOBDATA']->load();
    // If any text (or whitespace!) is printed before this header is sent,
    // the text won't be displayed and the image won't display properly.
    // Comment out this line to see the text and debug such a problem.
    header("Content-type: image/JPEG");
    echo $result;
    oci_free_statement($stmt);
    oci_close($conn); // log off
    ?>
    I get an error -can't open file htdocs/ phpA.tmp
    please if you have an idea from where it could be the error reply

    It looks like your webserver doesn't have read permissions on the directory and files within it. In Linux, set it to 755, in Windows, I'm not sure what needs doing sorry.

  • Random Image not displaying in Live View.

    My page is at:
    www.andrewjamesartist.co.uk
    There's a random image script on the front page.
    <img src="randomimages/rotate.php" alt="A Sample Image from the work of Andrew James" />
    That's how it is placed in the page.
    It shows in preview in browser and it's OK live but it doesn't show in LiveView.
    I use a testing server set up with virtual hosts.
    Martin

    My page is at:
    www.andrewjamesartist.co.uk
    There's a random image script on the front page.
    <img src="randomimages/rotate.php" alt="A Sample Image from the work of Andrew James" />
    That's how it is placed in the page.
    It shows in preview in browser and it's OK live but it doesn't show in LiveView.
    I use a testing server set up with virtual hosts.
    Martin

  • Random Image PHP Scipt Issue

    I am using a
    PHP random image
    script on a site in which I have 2 different images on each
    templated page (random images throgh a site). The two images call
    to 2 different folders with the random image script in them (to get
    2 distinct images). Thus, 2 different random images. My issue is
    that it seems that most browsers at some point do not call for a
    new image but use what was there in the last page as it is the same
    name:
    http://ansano.com/asl/images/random/top/random_image.php
    or
    http://ansano.com/asl/images/random/bottom/random_image.php
    Any idea of how to force a browser to call the PHP script? Or
    how to change it so it works site wide?
    Thanks!!

    I've now been sitting looking for this for a while. I don't seem to be able to get it to work.
    Do I need to host to a folder first and then to the FTP server after?
    I don't seen to be able to find the new page (TEST PAGE) in the folder I used to publish the site to before I went online. Tried searching for it in finder but I don't get any results on (TESTPAGEfiles).
    I can see what you are talking bout I only publish to a local folder but I want to publish via the FTP option in iWeb.
    Thank you very much for helping me

Maybe you are looking for

  • IAC application throwing the error ITS_EXPRESSION_NOT_NUM

    Hi all, We are having some IAC applications, the older version is ECC 4.6 . All the applications are working fine there. Now that we have migrated from ECC 4.6C to ECC 6.0, we have just copied all the IAC applications to the new system. When tested i

  • Check marked titles are not feasible to synch.Mac to Iphone6

    Dear apple community, hopefully one of you can help me: I would like to synchronize my selected titles at my iTunes on my Mac to my iPhone 6. With my last iPhones this wasn't an issue, but when I synchronize now, it keeps songs that aren't selected a

  • Are there any recent tutorials or information for integrating Adobe Flex with Ruby on Rails 4?

    I've combed and searched extensively and most of the documentation is anywhere from 4 to 7 years old.  A lot of it focuses on outdated gems or libraries.  I've even seen Rails 2.0 as a focus for a lot of this information. I would just like to know if

  • Refresh Flex application only once.

    Hi All ,   In my Flex Application i am calling a function  like : applicationComplete = "addPanel(999999);" , which will add a panel. 999999 is nothing but flag. But i should refresh application  Only Once .... how to do that.. Thanks in Advance...

  • How to find my EJBs?

    i want to get the EJB in my servlet: the EJB is:ejb.archive.ArchiveManager i have configratured reference name:ejb/archive/archivemanager in SUN FORTE . Hashtable env = new java.util.Hashtable(1); //initialiate context try { initContext = new javax.n