Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post postloading with mysql images

    hello


    I am trying to post load images stored in mysql db. I have tried this script:

    <script type="text/javascript">
    //<![CDATA[
    function postLoad(){
    if(!window.name.match(/preLoad.complete/gi)){
    var images = new Array('img/EnglishOn.gif',
    'img/EnterOn.gif',
    'img/EntrerOn.gif',
    'img/FrenchOn.gif');


    var loader = new Array();
    for(var i=0; i<images.length; i++){
    loader[i] = new Image();
    loader[i].src = images[i];
    }
    window.name = 'preLoad.complete';
    }
    }
    //]]>
    </script>



    in my site it looks like this:

    <script type="text/javascript">
    //<![CDATA[
    function postLoad()
    {
    var images = new Array('image.php?id_obrazu=8','image.php?id_obrazu=9','image.php?id_obrazu=10');
    var loader = new Array();
    for(var i=0; i<images.length; i++)
    {
    alert("loading image: "+i);
    loader[i] = new Image();
    loader[i].src = images[i];

    }
    }
    //]]>
    </script></head>
    <body onload="postLoad()">


    and image.php is:

    <?
    include("operacje_baza.php");
    if(isset($id_obrazu))
    {
    mysqlconnect();//my function connecting to db
    $zapytanie="SELECT OBRAZ FROM MZM_ZDJECIE WHERE MZM_ZDJECIE.ID=$id_obrazu";
    $wynik=mysql_query($zapytanie);
    $row=mysql_fetch_array($wynik);
    header("Content-type: image/jpeg");
    echo $row['OBRAZ'];

    mysql_close();

    }

    ?>

    image.php works fine showing requested images but postLoading does not work. I get an alert from script with "loading image" and number but it does not postload.

    If any one have idea how to solve my problem please write it
    generally i need postloading images from mysql db

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Try this and see what it says in the alert.
    Code:
    for(var i=0; i<images.length; i++)
    {
      loader[i] = new Image();
      loader[i].onerror = function(){alert("Error loading "+this.src)};
      loader[i].onload = function(){alert("OK loading "+this.src)};
      loader[i].src = images[i];
    }

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i did it and it shows one alert window: "ok loading: server/image.php?id_obrazu=8". no error or another ok loading alerts. But this image (id=8) is already loaded while loading page, so post load does not work. Sorry for my lame questions but i have just started with php and js. Only have experience with coding in c++ and java.

    /edit
    i checked in ie and its working ok but in firefox still does not. any ideas why?
    Last edited by soseki; 08-02-2006 at 12:17 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •