Jump to content

making each photo a new page from template


Recommended Posts

People upload photos to my site. They go into a gallery. They are all linked. Right now when you click one they go nowhere. I want to be each photo to open in its own page with my comment system already on it. Should I be using templates? If so how? Heres code to the gallery page if needed.

 

And I'm using dreamweavers server behaviors. If that will cause a problem let me know. Still new to PHP but getting better...maybe.

 

Sorry to keep asking noob questions.

 

<?php require_once('myconn.php'); 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_Recordset1 = 40;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_myconn, $myconn);
$query_Recordset1 = "SELECT name, photopath, `state` FROM photo";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>

<div id="photos">
  <table border="">
  <?php $i=0; $numperpage=8; ?>
    <?php do { ?>
    <?php if ($i%$numperpage==0) echo "<tr>"; ?>
        <td align="center">
        <a href=<?php echo $row_Recordset1['photopath']; ?>/>
        <img src=<?php echo $row_Recordset1['photopath']; ?> height="200" width="200"/>

<br/> 

<?php echo $row_Recordset1['name']; ?><br/> <?php echo $row_Recordset1['state']; ?></td>
<?php $i++; if ($i%$numperpage==0) echo "</tr>"; ?>

        
      
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  </table>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
Share on other sites

yea you will basically write a class or function w/e you want and then each time open a link to a ViewPic.php page that populates the class with the details of the photo and the image comments blah blah

 

something like viewPhoto.php?id=14324131243

 

take that id number pull the info for the picture.. populate the template with the information and show it.

is that too brief an explanation?

Link to comment
Share on other sites

well you keep the photo information in the DB right? such as location on the server and size type blah blah right?

 

well what you do is make a PHP page specifically for viewing just a single photo.. say viewPage.php

 

in viewPage.php you would recieve the ID of the picture selected to view and using that ID pull the rest of the pictures information from the DB.

 

after its pulled you will plug that data into an html template of some sort and display it so the user. quite simple really.

 

 

as for comments.. they would have a spot in the DB as well with a ID that corresponds with the ID of the photo they are for. so that you can retrieve them at the same time and populate the html template

Link to comment
Share on other sites

ok I'm starting to get this. Thanks for staying with me. So in the php page we have a function that calls out to whatever photo the user selects grabs all the info connected to that photo then displays it in a template? Now the function code is whats getting me. when the photo is clicked how does it know where to go? and as for the id would i write something like "id=$id" and define id as whatever user selects. Does that make sense? Am I overthinking this? It doesn't seem this hard

Link to comment
Share on other sites

theres not a function persay.. perhaps that was a poor choice of words.. when your gallery script prints out the links to the photos w/e

 

change that link so that it points to a php page and using the GET method attach the ID of the photo... in the php page you'll write some code to pull the info from the DB of the photo that goes with the ID sent and also the comments that go with that ID. Then populate the html template with the information from the DB. Its classic retrieve/display.

Link to comment
Share on other sites

OK one more thing and then I'm gonna write it. I was thinking of pointing that photo link to a page before I came on here but then you wouldn't see the photos. Should I echo out the photos a different way? Is that right?  Also the function was confusing me because it sounded like a GET method so I'm glad it's that, much easier.  Anyway, what do you think?

Link to comment
Share on other sites

you'll still show the photo.. when you pull the URL of the photo out of the database you'll just plug that into your HTML template.

 

and allow the browser to handle it normally..

 

<img src='<?php echo($IMAGEURL) ?>' />

 

 

its the same thing you do for the image gallery only the page is specifically designed to view everything about that one photo.

shoot the hardest part of this is writing the html/css for the page display lol.

 

these forums work quite the same way.. take a look at the URL on for this page.. notice the topic ID being sent

searches the database for posts with that ID attached to them and then after some organizing of the results displays it on the page via an HTML template with all the DB data plugged into it.

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.