Jump to content

Getting image from database


NealeWeb

Recommended Posts

Ok i have been trying for a few days now with no success to show a image from my database but as this is the first time i have tried to use databases im having no luck, my problem is this...

 

I have an image gallery that shows a list of differnt galleries with the number of images inside it, like this....  General (10)

 

I have a form that allows me to add new galleries to the list and upload an image to be shown in the gallery list, i simply added a field in the categories table and called it category_img. I would like to make the list of galleries look better by having an image for each one like this....

 

gallery image.jpg

 

This is the code that generates and displays the list of galleries/categories but it is WAY to advanced and confusing for me to work out what to do, i have tried all sorts but only ever destroys what i already have or just does nothing at all, the closest i have got was displaying the name of the image, but no actual image.

 

<?php
                // initialization
$result_array = array();
$counter = 0;

$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);

// Category Listing

if( empty($cid) && empty($pid) )
{
	$number_of_categories_in_row = 1;

	$result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
					FROM gallery_category as c
					LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
					GROUP BY c.category_id" );
	while( $row = mysql_fetch_array( $result ) )
	{
		$result_array[] =      
     '<p><a href="gallery.php?cid=' . $row[0] . '">' .      
     $row[1] . '</a> (' . $row[2] . ')</p>';                  
}      
	mysql_free_result( $result );	

	$result_final = "<tr>\n";

	foreach($result_array as $category_link)
	{
		if($counter == $number_of_categories_in_row)
		{	
			$counter = 1;
			$result_final .= "\n</tr>\n<tr>\n";
		}
		else
		$counter++;

		$result_final .= "\t<td>".$category_link."</td>\n";
	}

	if($counter)
	{
		if($number_of_categories_in_row-$counter)
		$result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n";

		$result_final .= "</tr>";
	}
}

 

i could really do with some help as trying to learn this stuff is really hard when i have to work in my living room with children running around, my head has not stopped hurting in days.

Link to comment
Share on other sites

Not sure, but if you just want the images to show on the page you  can do this:

<html>

<body>

<?php

mysql_connect('localhost', 'user', 'pass');
mysql_select_db('database');

$find = "SELECT * FROM database";
$run = mysql_query("$find");

while($is = mysql_fetch_assoc($run))
{

$images = $is['Column_Name'];
$image_name = $is['Column_Name'];

print "<img src='$images'/><label>$image_name</label>";

}

?>
</body>

</html>

Link to comment
Share on other sites

No, it will work, but as far as I'm aware it can't be done in the same page as you need to output different header types.  It's easier if just the image path is stored in the database.

 

I think you'll need a page that displays the html, with the image source links pointing to something like getimage.php?imageid=1

Link to comment
Share on other sites

The actual gallery images are stored in folders because i followed a tutorial to make the gallery but i am trying to modify it on my own, tahts why some are stored in folders and some in the database, also i would love to be able to use a script like zenphoto or gallery or something similar i have downloaded and attempted neaarly all of them but i have a site design that i need to be able to fit one of those scripts into and that seems like an even harder challenge than learning all the code from scratch.

Link to comment
Share on other sites

I started learning web design a while ago and i made the mistake of promising my cousin a site and designed it the way he wanted it because i thought i would be able to do it but i guess i should have been sure before i made any promises but its too late for that and i just dont want to let him down now.

 

This is the way i need it to look...

 

Design.jpg

 

And this is the basic plan i came up with for the site...

 

Gallery Page: List of galleries(Thumbnail for each gallery), inside galleries = image thumbnails with individual image rating and commenting with a jquery plugin preview to view large images.

 

 

Manage Site Page: (link echoed after log in) > multiple image upload into selected gallery(category), option to add a new gallery(category) and change photo or text on home and about page.

 

 

Contact page: email form (I can do this).

 

 

About page: changeable photo and page text.

 

 

Home page: changeable page text.

 

 

Login form on each page, when logged in stay on same page but show link to manage site page below a welcome user message where the form was.

Link to comment
Share on other sites

Ok i didnt expect that image to be so big. Anyway that is how i need it to look, or at least very close to that. And with my limited experience integrating all the code from something like zenphoto  into this design seems impossible, i would not have a clue where to start.

Link to comment
Share on other sites

I have yes, i have installed joomla, drupal, gallery, gallerific, zenphoto, 4images, wordpress, coppermine, tiny webgallery, piwigo, phpalbum and MANY more thinking that i will somehow be able to integrate in with my design but same as always as soon as they are installed im at a dead end, i have no idea what to do next, i have been through the pages of code seeing if i can spot which parts to copy or how to insert my design but i never get any where, i barely understand any of the code i am still only part way through the chapters on the w3schools site. I know i have no right expecting to be able to do this with the little i have learned so far but im trying allday everyday and i just need a break.

Link to comment
Share on other sites

I dont know if this will help you help me but this is the tutorial i have been following and all i need is a way to be able to show the list of categories with a thumbnail image that i upload when adding new categories, its frustrating because for days i have been pulling my hair out because i know it would just take a few more lines of code on the viewgallery.php page and on the page where i add new categories and maybe a new table or some fields in the database but i cant do any of it. i feel so stupid.

 

http://articles.sitepoint.com/article/php-gallery-system-minutes

Link to comment
Share on other sites

Ok i have tried a few things and have had no luck, i am a begginer so i could do with some schooling, below is the code that generates a list of galleries and the number of images in that gallery, what i want is to be able to display a thumbnail that i upload every time i make a new gallery above the gallery name in the list (the code for adding a new gallery is also below) i need help altering my database to make a place for the uploaded thumbnails and also modifying the code that generates the gallery list in order to display the thumbnails and also the add new category form to upload the image.

 

Category Listing... (This is it live at the moment)

 

<?php
                // initialization
    $result_array = array();
    $counter = 0;

    $cid = (int)($_GET['cid']);
    $pid = (int)($_GET['pid']);

    // Category Listing

    if( empty($cid) && empty($pid) )
    {
        $number_of_categories_in_row = 4;

        $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id" );
        while( $row = mysql_fetch_array( $result ) )
        {
            $result_array[] =      
     '<a href="gallery.php?cid=' . $row[0] . '">' .      
     $row[1] . '</a> (' . $row[2] . ')';                  
}      
        mysql_free_result( $result );    

        $result_final = "<tr>\n";

        foreach($result_array as $category_link)
        {
            if($counter == $number_of_categories_in_row)
            {    
                $counter = 1;
                $result_final .= "\n</tr>\n<tr>\n";
            }
            else
            $counter++;

            $result_final .= "\t<td>".$category_link."</td>\n";
        }

        if($counter)
        {
            if($number_of_categories_in_row-$counter)
            $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n";

            $result_final .= "</tr>";
        }
    } 

 

Add new category... (This is it live at the moment)

 

<?php

if (isset($_POST['submit'])):

  $category_name = $_POST['category_name'];
mysql_query( "INSERT INTO gallery_category(`category_name`) VALUES('".addslashes( $category_name )."' )" );

   
  if (@mysql_query($sql)) {
    echo('<p>New category added</p>');
  } else {
    echo('<p>New category added</p>');
  }
?>

<p><a href="<?=$_SERVER['PHP_SELF']?>">Add another category</a></p>

<?php
  else: // Allow the user to enter a new category
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p><br />
New Category: <input type="text" name="category_name" size="20" maxlength="255"/><br />
<input type="submit" name="submit" value="SUBMIT" /></p>
</form>

<?php endif; ?> 

 

And this is how id like them to look when finished...

 

Gallery Listing

gal.jpg

 

Add new category

adcat.jpg

 

 

 

Link to comment
Share on other sites

All i need is someone to tell me how i can get the code below to also display a single thumbnail from the category above the category name.

 

Category and Thumbnail listing code...

if( empty($cid) && empty($pid) )
    {
        $number_of_categories_in_row = 4;

        $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id ");
        while( $row = mysql_fetch_array( $result ) )
        {
            $result_array[] =      
     '<a href="gallery.php?cid=' . $row[0] . '">' .      
     $row[1] . '</a> (' . $row[2] . ')';                  
}      
        mysql_free_result( $result );    

        $result_final = "<tr>\n";

        foreach($result_array as $category_link)
        {
            if($counter == $number_of_categories_in_row)
            {    
                $counter = 1;
                $result_final .= "\n</tr>\n<tr>\n";
            }
            else
            $counter++;

            $result_final .= "\t<td>".$category_link."</td>\n";
        }

        if($counter)
        {
            if($number_of_categories_in_row-$counter)
            $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n";

            $result_final .= "</tr>";
        }
    }


    // Thumbnail Listing

    else if( $cid && empty( $pid ) )
    {
        $number_of_thumbs_in_row = '1';

        $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" );
        $nr = mysql_num_rows( $result );

        if( empty( $nr ) )
        {
            $result_final = "\t<tr><td>No Gallery found</td></tr>\n";
        }
        else
        {
            while( $row = mysql_fetch_array( $result ) )
            {
    $result_array[] = "<a href='".$images_dir."/full_".$row[2]."' rel=\"lightbox\"><img src='".$images_dir."/tb_".$row[2]."' border='3' style='margin: 4px;' bordercolor='silver' alt='".$row[1]."' /></a>";
            }
            mysql_free_result( $result );    

            $result_final = "<tr>\n";
    
            foreach($result_array as $thumbnail_link)
            {
                if($counter == $number_of_thumbs_in_row)
                {    
                    $counter = 1;
                    $result_final .= "\n</tr>\n<tr>\n";
                }
                else
                $counter++;

                $result_final .= $thumbnail_link;
            }
    
            if($counter)
            {
                if($number_of_photos_in_row-$counter)
            $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'> </td>\n";

                $result_final .= "</tr>";
            }
        }
    }  

 

the link below is to the page that lists the categories, when you click on a category it shows you all the thumbnails, i want to be able to show any one of those thumbnails above the category name in the list of categories. Im sure it must be really simple but nothing im trying is working. http://www.nealeweb.com/auto2/gallery.php Please help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.