i am only display 10 images on this page but it takes like 4sec to load. which is alot, i should take like 1 or 2 sec to load. any thoughts?
i also tired joining sql

<?php
include("include/header.php");

//check, if user is loged in or not
if(isset($_SESSION['username']))      /*** user is loged in ***/
{
    $user = $_SESSION['username'];    //get name of who is loged in

    $count = 0;
    $Q = "SELECT (SELECT image_short_name FROM user WHERE username = '$user') as `image_short_name`"
    .",`image_id`,`user_id`,`image_short_name`,`image`"
    ." FROM `image`"
    ." ORDER BY RAND()"
    ." LIMIT 10";
    $R = mysql_query($Q);

    echo "
        <head>
            <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
            <link rel='stylesheet' type='text/css' href='css/all_css.css' />
        </head>

        <div id ='bg4'>
            <div id='context4'>

                <table  width='1000px' height='500px' cellpadding='45px'>                       
                    <tr height='100px'>     
                    ";           
                        while($row = mysql_fetch_assoc($R))
                            {
                                //get user_id from image table
                                $user_id_r         = $row['user_id'];
                                $image_short_name_r = $row['image_short_name'];

                                //get user name from user table
                                $queryget = mysql_query("SELECT username FROM user WHERE user_id = '$user_id_r'") ;
                                $row2 = mysql_fetch_assoc($queryget);   
                                $user_name_db = $row2['username'];

                                echo "<td width='100px'>";
                                $image_db = $row['image'];
                                $src = "data:image/gif;base64," . $image_db;
                                echo" <a href='zoom.php'><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>";
                                echo "<center id='image_name'><a href='zoom.php'>" . $image_short_name_r . "</a></center>";
                                echo " <center id='image_name2'>by $user_name_db</center>";
                                echo "</td>";
                                $count++;
                                if($count == 5)       //5 rows
                                {
                                    echo "</tr><tr height='100px'>"; // Start a new row at 6 cells
                                    $count = 0;
                                }
                            }
                echo " 
                    </tr>
                </table>

            </div>
        </div>   
        ";
}
else
{
    echo "
        <head>
            <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
            <link rel='stylesheet' type='text/css' href='css/all_css.css' />
        </head>

        <div id ='bg'>
            <div id='context'>
            </div>
        </div>
        ";
}
?>

It is slow because everytime you are loading random images from the database, and displaying them inline. The browser cannot cache this. For better performance, you could store the files on disk, and just read the filenames from the database.

further to pritaeas accurate answer,

you appear to be resizing large images in the browser, (resized thumbs typically get a prefix or suffix when created) a large image is downloaded then displayed 130x130px,
resize the image at the server then serve the thumbnail image, 130x130 is 4 times smaller than 260x260 4 times faster
(typically a large image is uploaded, a thumbnail is created and also stored, the thumbnail is served, and the full size image ling by (in this case zoom.php)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.