Jump to content



Photo

Adding Images To Browse_Prints.Php

images

  • Please log in to reply
12 replies to this topic

#1 00cakea

00cakea

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 8 February 2012 - 4:06 PM

Hi guys, in need of some help attaching images to the table on the browse_prints.php page, is this possible to do?

Sorry I am pretty new to php and have tried playing around with some code but only get errors - I have managed to get the 'request image is not available' image to appear in the table so think im not too far off.

If anyone has managed to do this or could be off assistance would be great to hear from you!

Thanks
  • 0

#2 margaux

margaux

    Advanced Member

  • Members
  • PipPipPip
  • 449 posts

Posted 8 February 2012 - 6:55 PM

I did get this to work. Not sure exactly what your question is, could you be more specific?
  • 1

#3 00cakea

00cakea

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 9 February 2012 - 6:11 AM

Sorry I was a little vague!

I was basically wondering how I would go around trying to implementing this - what code would I need to add to the table to get this to work?

Thanks
  • 0

#4 margaux

margaux

    Advanced Member

  • Members
  • PipPipPip
  • 449 posts

Posted 10 February 2012 - 11:40 AM

browse-prints.php is part of the ecommerce example. You need to provide your own images, store them in a directory and set up the database which accesses the filename of the images. Ideally use the admin functions addArtist.php and addPrint.php to populate the d/b and get the files stored in the correct directory. If you work through the beginning of the chapter you'll set up the database, file structure and admin functions.

I've modified the scripts to enable a client to upload images to his portfolio site - a mini CMS without the ecommerce side.
  • 0

#5 00cakea

00cakea

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 10 February 2012 - 5:31 PM

browse-prints.php is part of the ecommerce example. You need to provide your own images, store them in a directory and set up the database which accesses the filename of the images. Ideally use the admin functions addArtist.php and addPrint.php to populate the d/b and get the files stored in the correct directory. If you work through the beginning of the chapter you'll set up the database, file structure and admin functions.

I've modified the scripts to enable a client to upload images to his portfolio site - a mini CMS without the ecommerce side.


Thanks for the help

I have set up the database and populated and currently have prints (with details) correctly displayed on browse_prints.php in the table, the links for each print also work and take me through to view_prints.php with the image displayed.

What I wanted to know was how to get this image to also appear in the table of prints on the browse_prints page.

Does anyone have a solution for this - I keep getting errors
  • 0

#6 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,693 posts
  • LocationColumbus, OH USA

Posted 10 February 2012 - 8:32 PM

"I ... currently have prints (with details) correctly displayed on browse_prints.php in the table, [but] ... I wanted to know how to get this image to also appear in the table of prints on the browse_prints page."




What do you mean?
You mean you want to add additional pics to the table?
  • 0

#7 00cakea

00cakea

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 11 February 2012 - 5:12 AM

Yes that is what i want to know!!!!

Currently as followed via the tutorial in the book browse_prints is not set up to display the images, how to i go about changing the php to add the image to the prints table?
  • 0

#8 margaux

margaux

    Advanced Member

  • Members
  • PipPipPip
  • 449 posts

Posted 11 February 2012 - 2:19 PM

ok I think I get what you are trying to do, sorry for not getting it the first time. You'll need to do some formatting/image re-sizing to get a nice display but here's what worked for me.
<?php
$page_title = 'Display the Prints';
include ('includes/header.html');
require ('includes/mysqli_connect.php');

$q= "SELECT artists.artist_id, CONCAT_WS(' ', firstname, middlename, lastname) AS artist, printname, price, description, print_id, imagename
FROM artists, prints WHERE artists.artist_id = prints.artist_id ORDER BY artists.lastname ASC, prints.printname ASC";

if (isset($_GET['aid']) && filter_var($_GET['aid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) {
    $q = "SELECT artists.artist_id, CONCAT_WS(' ', firstname, middlename, lastname) AS artist, printname, price, description, print_id, imagename
    FROM artists, prints WHERE artists.artist_id = prints.artist_id  AND prints.artist_id={$_GET['aid']} ORDER BY prints.printname";
    }
echo '<table border="0" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="15%"><b>Artist</b></td>
<td align="left" width="25%"><b>Thumbnail</b></td>
<td align="left" width="15%"><b>Print Name</b></td>
<td align="left" width="20%"><b>Description</b></td>
<td align="right" width="5%"><b>Price</b></td>
</tr>';
$r = mysqli_query($dbc, $q)  or trigger_error("Query: $q\n <br />MySQL Error: " . mysqli_error($dbc));

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$image = $row['imagename'];
$pid = $row['print_id'];
echo "<tr><td align=\"left\"><a href=\"browsePrints.php?aid={$row['artist_id']}\">{$row['artist']}</a></td>";
    if ($image = @getimagesize ("../uploads/$pid")) {
            echo "<td align=\"center\"><img src=\"showPrint.php?image=$pid&name=" . urlencode($row['imagename']) . "\" $image[3] alt=\"{$row['printname']}\" />
            </td>\n";
    }

echo "<td align=\"left\"><a href=\"viewPrint.php?pid={$row['print_id']}\">{$row['printname']}</td>
<td align=\"left\">{$row['description']}</td>
<td align=\"right\">{$row['price']}</td>
</tr>\n";
}
echo '</table>';
mysqli_close($dbc);
include ('includes/footer.html');
?>

  • 1

#9 margaux

margaux

    Advanced Member

  • Members
  • PipPipPip
  • 449 posts

Posted 11 February 2012 - 2:39 PM

<p>I changed the code that calls showPrint.php to [code=auto:0]
echo "
  • 0

#10 giantsfan24

giantsfan24

    Member

  • Members
  • PipPip
  • 32 posts

Posted 11 February 2012 - 11:00 PM

Good point about the image resizing and formatting! A quick google search should find a quick bit of code for 00cakea to limit the size and placement of the shown image, such as applying some CSS.

Also your first instance of creating the $image variable seems unnecessary(isn't it?), since you re-assign the variable a couple lines down anyway and never use it outside the if conditional there.

I do admire your ability to improvise, since that seams to be a large portion of programming. Trust me when I tell you I am not speaking from superiority, since you are likely a better programmer than me. Good job!!!
  • 0

#11 margaux

margaux

    Advanced Member

  • Members
  • PipPipPip
  • 449 posts

Posted 12 February 2012 - 11:01 AM

@giantsfan24 - good point, there is actually no need to create the first instance of $image, can't remember what I was thinking when I created it.

In my previous post, the amended code didn't show up so here it is,
if ($image = @getimagesize ("../uploads/$pid")) {
   echo "<td align=\"center\"><img src=\"showPrint.php?image=$pid&name=" . urlencode($row['imagename']) . "height=\"200\" width=\"200\" alt=\"{$row['printname']}\" />
   </td>\n";

nothing new logically, just a height and width on the image tag to help with the display. Probably not the best way performance wise as I think all this re-sizing could slow down the page load.
  • 1

#12 00cakea

00cakea

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 12 February 2012 - 6:19 PM

Many thanks for your help - seem to have it working now which is brilliant! :)
  • 0

#13 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,693 posts
  • LocationColumbus, OH USA

Posted 12 February 2012 - 7:41 PM

I think the resizing itself is not that bad, but if you're loading a 2 MB image file that's shrunk down to a 50 x 50 thumbnail pic, then you could probably do better. I think there are some JavaScript/jQuery interfaces out there for point-and-click resizing an image and then saving a thumbnail as a separate image. In general, it's best to create and save separate thumbnails.
  • 0