trying to buld gllery.php page. where i want to print all user image with 4 cols. and infity rows. all in one page

gallery.php

<?php
session_start();
include("connect.php");

$user = $_SESSION['username'];
if($user)
{
    $user_id = $_SESSION['user_id']; //get user_id who ever is loged in

    $image = mysql_query("SELECT * FROM image WHERE user_id = $user_id ORDER BY image_id DESC");
    //$image = mysql_fetch_assoc($image); //get access to image table
    $image = $image['image'];
    base64_decode($image); 

    echo "your gallery<br/><br/><br/>";
    echo "<a href='upload.php'>upload image</a>";
    echo "<a href='index.php'>home</a><br/><br/><br/>";

    echo '<table>'; // Your table
    echo '<tr>'; // first table row
    $count = 0;
    while($image = mysql_fetch_assoc($image))
    {
        echo"
            <td>                                                  //how to do it with using get.php
                <img src=\"get.php?image_id=$lastid\"></img>//print image
            </td>
        ";
        $count++;
        if($count == 4)
        {
            echo '</tr><tr>'; // Start a new row at 4 cells
            $count = 0;
        }
    }
    echo '</tr>';
    echo '</table>';

}
?>

Recommended Answers

All 10 Replies

Have a look here: http://php.net/manual/en/function.mysql-fetch-assoc.php

$image seem's to be very popular variable, the below is not tested

session_start();
include("connect.php");
$user = $_SESSION['username'];
if($user)
{
    $user_id = $_SESSION['user_id']; //get user_id who ever is loged in
    $sql = "SELECT * FROM image WHERE user_id = $user_id ORDER BY image_id DESC";
}

echo "your gallery<br/><br/><br/>";
echo "<a href='upload.php'>upload image</a>";
echo "<a href='index.php'>home</a><br/><br/><br/>";
echo '<table>'; // Your table
echo '<tr>'; // first table row


$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}
$n = 0;
while ($row = mysql_fetch_assoc($result)) 
{
    echo"<td> //how to do it with using get.php
        <img src=\"get.php?image_id=$lastid\"></img>//print image
        </td>";

    $n++;
    if($n == 4)
    {
        echo '</tr><tr>'; // Start a new row at 4 cells
        $n = 0;
    }
}
echo '</tr>';
echo '</table>';
commented: thanks alot +0

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\login_test\gallery.php on line 22

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\xampp\htdocs\login_test\gallery.php on line 23

<?php
session_start();
include("connect.php");

$user = $_SESSION['username'];
$user_id = $_SESSION['user_id']; //get user_id who ever is loged in
if($user)  //is user is loged in 
{
    $sql = mysql_query("SELECT * FROM image WHERE user_id = $user_id ORDER BY image_id DESC");
    //$image = mysql_fetch_assoc($image); //get access to image table
    //$image = $image['image'];
    //base64_decode($image); 

    /*** table which holds images ***/
    echo "your gallery<br/><br/><br/>";
    echo "<a href='upload.php'>upload image</a>";
    echo "<a href='index.php'>home</a><br/><br/><br/>";

    echo '<table>'; // Your table
    echo '<tr>'; // first table row
    $count = 0;
    $result = mysql_query($sql);
    while($row = mysql_fetch_assoc($result))
    {
            echo"
                <td>       //how to do this without using get.php
                    <img src=\"get.php?image_id=$lastid\"></img>
                </td>
            ";
            $count++;
            if($count == 6)       //6 rows
            {
                echo '</tr><tr>'; // Start a new row at 4 cells
                $count = 0;
            }
    }
    echo '</tr>';
    echo '</table>';

}
?>

You have changed line 9. remove the "mysql_query" and ()

`$sql = "SELECT * FROM image WHERE user_id = $user_id ORDER BY image_id DESC";'

You would need to address <img src=\"get.php?image_id=$lastid\"></img> as it would be $row['lastid'] it $lastid is from DB

commented: thanks +2

last question how do i print all the images.

<img src=\"get.php?image_id=$lastid\"></img>

bc of this i print only last image, which is bc of $lasid i think.
i want to print all the image 100X100.

hwoarang69

<img src='get.php?image_id=$row[lastid]'>

i would suggest resizing the image during the upload process, as resizing in the browser will slow it down

commented: ty +0

ops i ment i didnt wanted to use get.php to display image.
I think is that i could have to do this

   $image = $image['image'];      //not sure if its $image['image'] i think its $image['row']
    base64_decode($image); 
   <img src='$image'></img>

sorry long day today :)
<img src='get.php?image_id=$row[lastid]'> will only show one image.

<img src='$row[lastid]'> this is taking the assumption you have saved the image as the ID

commented: it almost worked +0

Notice: Undefined index: lastid in C:\xampp\htdocs\login_test\gallery.php on line 29
and broken links

$lastid = mysql_insert_id(); 
<img src='$row[lastid]' width='200' height='200'></img>

line 29 : $row[lastid]

This is assuming you are identifying the images by lastid, if you are you will still need to address the folder location of where the images are saved (guessing this is partly done in the get.php

$folderLoc = "PATH/TO/IMAGE/FOLDER";
<img src='$folderLoc/$row[lastid]/>

If not please show the code in the get.php file you dont wish to use

This is a gallery i did for the site owner:

http://www.helenshappyhome.co.uk/gallery.php

The content is dynamic depending on the gallery subject selected

I am getting error
Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\html5\login.php on line 30
Query Failed

    <?php


        include ('include/dbconfig.php'); 
        if (isset($_POST['formsubmitted'])) {
            // Initialize a session:
        session_start();
            $error = array();

            if (empty($_POST['e-mail'])) {//if the email supplied is empty 
                $error[] = 'You forgot to enter  your Email ';
            } else {

                if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {

                    $Email = $_POST['e-mail'];
                } else {
                     $error[] = 'Your EMail Address is invalid  ';
                }
            }
            if (empty($_POST['Password'])) {
                $error[] = 'Please Enter Your Password ';
            } else {
                $md5Password = md5($_POST['Password']);
            }
               if (empty($error))
            {  
                $query = "SELECT * FROM users WHERE email='$Email' AND password='$md5Password')";
                $query_check = mysql_query ($query);


                $result_check = mysql_query($link, $query_check);
                if(!$result_check){//If the QUery Failed 
                    echo 'Query Failed ';
                }

                if (@mysqli_num_rows($result_check) == 1)//if Query is successfull 
                { // A match was made.

                    $_SESSION = mysqli_fetch_array($result_check, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable

                    header("Location: page.php");
                }else
                {         
                    $msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect';
                }
            }  else {

        echo '<div class="errormsgbox"> <ol>';
                foreach ($error as $key => $values) {

                    echo '  <li>'.$values.'</li>';

                }
                echo '</ol></div>';
            }

            if(isset($msg_error)){       
                echo '<div class="warning">'.$msg_error.' </div>';
            }
            /// var_dump($error);
            mysql_close($link);

        } // End of the main Submit conditional.

?>

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.