php_beginner_83 Posted October 6, 2009 Share Posted October 6, 2009 Hi Everyone I need a little help. I'm trying to add user comments to a photo gallery. I have my main page and use include to add my photo gallery to it. I was also using a include to add the comments section. However, I'm having trouble getting the photo gallery and comments synced. I.e. How to display the comments for the picture being displayed. Any ideas on how to get this to work?? Thanks This is the code from the main page.. ... <body> <?php include('databaseconnection.php'); include('commentPage.php');?> </body> .... This is my photo gallery code.. $titles = array(); $descriptions = array(); $paths = array(); $ID = array(); $thumbDir = "thumbs/"; $previousLink = "<"; $nextLink = ">"; $firstLink = "«"; $lastLink = "»"; $space = "&ensp"; $counter = 0; //fetch tha data from the database while ($row = mysql_fetch_assoc($result)) { $ID[$counter] = $row['ID']; $descriptions[$counter] = $row['Description']; $paths[$counter] = substr(strrchr($row['Path'],92),1); $counter++; } $imgIndex = $_GET['img']; if(!isset($paths[$imgIndex])) { $imgIndex = 0; } $currentImage = "images//" . $paths[$imgIndex]; $desc = $descriptions[$imgIndex]; $currentID = $ID[$imgIndex]; echo "<div id=sidebar>"; // display the thumbnails for($i = 0; $i<sizeof($paths); $i++) { echo "<a href=\"".$_SERVER['SCRIPT_NAME']."?page=photo&img=".($i)."&ID=".$albumID."\">" . "<img src=\"" . $thumbDir . "/" . $paths[$i] . "\" alt=\"" . $paths[$i] . "\" />\n"; echo " </a>\n"; } echo "</div>"; if ($imgIndex<=0) { $prev = $previousLink . $space; } else { $prev = "<a href=\"".$_SERVER['SCRIPT_NAME']."?page=photo&img=".($imgIndex-1)."&ID=".$albumID."\">" . $previousLink . $space . "</a>"; } if ($imgIndex>=(count($paths)-1)) { $next = $space . $nextLink; } else { $next = "<a href=\"".$_SERVER['SCRIPT_NAME']."?page=photo&img=".($imgIndex+1)."&ID=".$albumID."\">" . $space . $nextLink . "</a>"; } echo "<div id='photoContent'>"; echo $prev . "<img src=\"{$currentImage}\">" . $next . "</br></br>"; echo "<p>" . $desc . "</p>"; echo "</div>"; mysql_close($dbhandle); This is my Guestbook code.. // enteries per page $entriesPerPage = 5; if(!isset($_GET['page'])) { $pageNo = 1; } else { $pageNo = $_GET['page']; } $offset = ($pageNo - 1) * $entriesPerPage; // query to get comments $query = "SELECT ID, Name, Comment, DateTime FROM comments WHERE Pic_ID = 58 ORDER BY ID DESC LIMIT $offset, $entriesPerPage"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) == 0) { echo "Guestbook is empty"; } else { while($row = mysql_fetch_array($result)) { list($ID, $name, $comment, $date) = $row; echo '<table width="500" border="2">'; echo '<tr><td width="100">' . $date . '</td>'; echo '<td>' . $name . '</td></tr>'; echo '<tr><td colspan="2">' . $comment . '</td></tr>'; echo '</table>'; echo '<br/>'; } } $sql = "SELECT COUNT(ID) AS numOfRows FROM comments"; $result1 = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result1, MYSQL_ASSOC); $numOfRows = $row['numOfRows']; $maxPage = ceil($numOfRows/$entriesPerPage); $nextLink = ''; if($maxPage > 1) { $self = $_SERVER['PHP_SELF']; $nextLink = array(); for($page = 1; $page <= $maxPage; $page++) { $nextLink[] = "<a href=\"$self?page=$page\">$page</a>"; } $nextLink = "Go to page : " . implode(' » ', $nextLink); echo $nextLink; } ?> Link to comment https://forums.phpfreaks.com/topic/176628-photo-gallery-with-user-comments-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.