jbuck20 Posted April 9, 2010 Share Posted April 9, 2010 I've created a picture gallery that displays 12 records per page and produces the proper amount of pages per request. When the thumbnail is clicked on the left part of the screen, the larger image appears on the right and displays the three pieces of data from the MySQL record. Only the first piece of data is changing with the request and the second two pieces stay static until the page is changed. Here are some snippets of my code: // get the name for the main image if (isset($_GET['image'])) { $image = $_GET['image']; } else { $image = $row['image']; } $id = $row['id']; $title = $row['title']; $dimensions = $row['dimensions']; $media = $row['media']; ----- // initialize cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['image'] == $image) { $title = $row['title']; } ------ <div id="mainpic"> <img src="images_art/<?php echo $image; ?>" id="mainpic" alt="<?php echo $title; ?>" <?php echo $imageSize[3]; ?>/><br /> <p id="picCaption"><?php echo $title.", ".$media.", ".$dimensions;?> </p> Any suggestions would be of major help. I'm stumped. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/ Share on other sites More sharing options...
ChemicalBliss Posted April 9, 2010 Share Posted April 9, 2010 huh? Here are a couple tips: 1. Use PHP Code Tags with Full code pages, not snippets - errors can come from the start of a script.. 2. Explain your Idea, Then Your Code, Then Your Problem or Errors with Expected output. ----- From what youve given us, i would assume your trying to create some type of real-time thumbnail gallery, eg, 12 thumbnails on a page, you click one and it immediately shows the full size. For this you will need to use ajax, (javascript + php). -CB- Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/#findComment-1039519 Share on other sites More sharing options...
jbuck20 Posted April 9, 2010 Author Share Posted April 9, 2010 Here's the full code for the page: <?php require_once('../Connections/connect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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; } } //get available pieces from db $date = $_GET['date']; mysql_select_db($database_connect, $connect); $query_query = "SELECT * FROM pieces WHERE category_id='1' AND date='$date'"; $query = mysql_query($query_query, $connect) or die(mysql_error()); $row_query = mysql_fetch_assoc($query); $totalRows_query = mysql_num_rows($query); //define number of columns in table define ('COLS', 3); //set maximum number of records per page define ('SHOWMAX', 12); //create a connection to MySQL //prepare SQL to get total records $getTotal = "SELECT COUNT(*) FROM pieces WHERE category_id='1' AND date='$date'"; //submit query and store result as $totalPix $total = mysql_query($getTotal); $row = mysql_fetch_row($total); $totalPix = $row[0]; // set the current page $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; //calculate the start row of the subset $startRow = $curPage * SHOWMAX; //prepare SQL to retrieve subset of image details $sql = "SELECT * FROM pieces WHERE category_id='1' AND date='$date' LIMIT $startRow,".SHOWMAX; //submit the query (MySQL original) $result = mysql_query ($sql) or die(mysql_error()); //extract the first record as an array $row = mysql_fetch_assoc($result); //get the value of the last page $lastPage = ceil ($totalPix/12)-1; // get the name for the main image if (isset($_GET['image'])) { $image = $_GET['image']; } else { $image = $row['image']; } $id = $row['id']; $title = $row['title']; //$date = $row['date']; $dimensions = $row['dimensions']; $media = $row['media']; //get the dimesions of the main image $imageSize = getimagesize('images_art/'.$image); $thumbSize = getimagesize('images_art/thumbs/'.$image); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Alfredo Gisholt</title> <?php include('style_rules.php'); ?> </head> <body> <div id="wrapper"> <!--start wrapper--> <div id="titlebar"> <!--start title bar --> <a href="index.php"><img src="images/name.gif" alt="Alfredo Gisholt" width="231" height="32" border="0" /></a> <!--end title bar --> </div> <div id="leftcol"> <div id="nav"> <?php include('navmenu.php'); ?> </div> </div> <div id="maincontent"> <!--start main content --> <h1>Paintings - <?php echo $date; ?></h1> <div id="gallery"> <div id="thumbnails"> <table> <tr> <!--This row needs to be repeated--> <?php // initialize cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['image'] == $image) { $title = $row['title']; } ?> <td align="center"><a href="<?php echo $_SERVER['PHP_SELF'];?>?date=<?php echo $_GET['date']; ?>&image=<?php echo $row['image']; ?>&curPage=<?php echo $curPage; ?>"><img src="images_art/thumbs/<?php echo $row['image']; ?>" alt="<?php echo $row['title']; ?>" /></a></td> <?php $row = mysql_fetch_assoc($result); // increment counter after next row extracted $pos++; // if at end of row and records remain, insert tags if ($pos%COLS === 0 && is_array($row)) { echo '</tr><tr>'; } } while($row); // end of loop // new loop to fill in final row while ($pos%COLS) { echo '<td> </td>'; $pos++; } ?> </tr> </table> <!-- Navigation link needs to go here --> <table border="0"> <tr id="pageNav"> <td width="64"><?php // create a forward link for first page of records if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?date='.$_GET['date'].'&curPage=0"><< First</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <td width="140"><?php // create a back link if current page greater than 0 if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?date='.$_GET['date'].'&curPage='.($curPage-1).'">< Prev</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 2 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td width="50"><?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?date='.$_GET['date'].'&curPage='.($curPage+1).'">Next></a>'; } // otherwise leave the cell empty else { echo ' '; } ?></td> <td width="50"><?php // create a forwards link for last group of records if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?date='.$_GET['date'].'&curPage='.($lastPage).'">Last >></a>'; } // otherwise leave the cell empty else { echo ' '; } ?></td> </tr> </table> </div> <div id="mainpic"> <img src="images_art/<?php echo $image; ?>" id="mainpic" alt="<?php echo $title; ?>" <?php echo $imageSize[3]; ?>/><br /> <p id="picCaption"><?php echo $title.", ".$media.", ".$dimensions;?> </p> </div> </div> </div> <!--end main content --> <div id="footer"> <?php include('assets/copyright.php'); ?> </div> </div> <!--end wrapper --> </body> </html> <?php mysql_free_result($query); ?> you can see how the page works currently at http://alfredogisholt.com/pieces.php?date=2008. When you click on the thumbnail, the large image and title underneath the picture change, but the two pieces of data after the title remain static. Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/#findComment-1039526 Share on other sites More sharing options...
ChemicalBliss Posted April 9, 2010 Share Posted April 9, 2010 If you want the best chance of help use [code[ or tags, its extremely difficult to read unformatted code, and i doubt anyone will bother to import it into their text editor. -Also, please confirm wether you want real time etc, what do you want it to do?? -CB- Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/#findComment-1039530 Share on other sites More sharing options...
wordman Posted April 13, 2010 Share Posted April 13, 2010 From what youve given us, i would assume your trying to create some type of real-time thumbnail gallery, eg, 12 thumbnails on a page, you click one and it immediately shows the full size. For this you will need to use ajax, (javascript + php). -CB- Actually, i have mine working with PHP and a MySQLi database. No Javascript. As an FYI, the book 'PHP Solutions' by David Powers covers this exact topic in depth. It's also an excellent book. Cheers, wordman Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/#findComment-1040647 Share on other sites More sharing options...
jbuck20 Posted April 13, 2010 Author Share Posted April 13, 2010 thanks wordman. i read David Powers' book which was very helpful. Unfortunately, his gallery solution was a bit simpler since his caption was one piece of data, where as I have three pieces of data to as the the caption. Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/#findComment-1040678 Share on other sites More sharing options...
wordman Posted April 13, 2010 Share Posted April 13, 2010 jbuck, I just made a major move forward with my gallery which is adapted from Powers' code. Yes, his gallery is beautifully simple, and it has taken me a long time to modify it as I'm learning php and MySQL as I go. I have, however, accomplished this with the code: After making a few selections, the user is presented with a TOC (table of contents) page based on query string data from previous pages. The TOC page displays galleries relevant only to the query string value, BUT, I can display as many as I want, as I also just got the pagination to work correctly (major headache for me). The splitting pain that was in my head is gone now and I am working on finalizing the TOC design. I would be HAPPY to share what I know with you, if what I know will help. I hate to ask this, because I hate it when I get asked to do this, but...could you be more specific with what you want to happen? What I have just achieved may help you. Just let me know! This forum rocks. Cheers, wordman Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/#findComment-1040713 Share on other sites More sharing options...
ChemicalBliss Posted April 13, 2010 Share Posted April 13, 2010 From what youve given us, i would assume your trying to create some type of real-time thumbnail gallery, eg, 12 thumbnails on a page, you click one and it immediately shows the full size. For this you will need to use ajax, (javascript + php). -CB- Actually, i have mine working with PHP and a MySQLi database. No Javascript. As an FYI, the book 'PHP Solutions' by David Powers covers this exact topic in depth. It's also an excellent book. Cheers, wordman I meant if he doesnt want the page to refresh or to open a new window, he will need to use ajax, for example - to change a pre-existing element on the page without having to load the whole page again wasting precious bandwidth. If however you want it in a new window thats obviously easy. If yhou want it to refresh the page, or an iframe thats easy too. But thats not what i got from his explanation. - This is irrelevant now hoever since he is refreshing his page. ------ Just to repeat one last time please for quick decent help, post tagged code ( code here.. ), with your Problem, and Exepected Output etc. To your Solution: Anyway from looking at your site i see what you mean, it shows the image name, but not the other two details. So, You have a design flaw in your code: $media and $dimensions. These two variables are always being set by the $row variable, the statement that gets that row is always the same therefor the variables are always the same. Im sure you can figure this out, I would suggest trying to organise your code into easily readable segments. **NOTE** - Please secure your code, it is possible to delete your mysql database, and do lots, and lots of other freaky stuff by way of: XSS and SQL Injection. Google Common PHP Security for more details. -CB- -CB- Link to comment https://forums.phpfreaks.com/topic/198127-record-data-doesnt-display-correctly/#findComment-1040856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.