yandoo Posted August 30, 2009 Share Posted August 30, 2009 Hi there, My code isnt functioning correctly. It outputs records from a database including an image. There are 2 small probs that i think may be related. When the record are displayed an empty image field is outputted above the records??? The other thing is that the pagnation doesnt appear to be functioning correcly. I only have 2 records in the db at the mo but when i limit to only 1 record, both are still displayed along with hte navagation links??? The nav links dont do anything when clicked either. I been looking for ages and was hoping for somebody with some fresh eyes could have a look. Thank You <?php if (!isset($_SESSION)) { session_start(); } $file_dir = "E:/wamp/www/greenlife/Uploads/"; $link_dir = "./Uploads/"; $file_url = "http://localhost/greenlife/Uploads/"; $currentPage = $_SERVER["PHP_SELF"]; $maxRows_sql = 1; $pageNum_sql = 0; if (isset($_GET['pageNum_sql'])) { $pageNum_sql = $_GET['pageNum_sql']; } $startRow_sql = $pageNum_sql * $maxRows_sql; $colname_sql = "-1"; <?php $date = date("M"); //$month = 'May'; mysql_select_db($database_connect, $connect); $query_sql = 'select V.VegeID,V.Name, Moisture, Hardiness, Light, HarvestInDays, Image from vegetable V,outdoorsowtime S where S.'.$date.' = 1 and V.VegeID = S.VegeID'; $sql = mysql_query($query_sql, $connect) or die(mysql_error()); if (isset($_GET['totalRows_sql'])) { $totalRows_sql = $_GET['totalRows_sql']; } else { $all_sql = mysql_query($query_sql); $totalRows_sql = mysql_num_rows($all_sql); } $totalPages_sql = ceil($totalRows_sql/$maxRows_sql)-1; $queryString_sql = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_sql") == false && stristr($param, "totalRows_sql") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_sql = "&" . htmlentities(implode("&", $newParams)); } } $queryString_sql = sprintf("&totalRows_sql=%d%s", $totalRows_sql, $queryString_sql); <?php do { ?> <table width="100%" border="1"> <tr> <td width= "222" ><a href="vege_details.php?recordID=<?php echo $row_sql['VegeID']; ?> "><?php echo $row_sql['Name']; ?></a></td> <td width= "101" ><?php echo $row_sql['Moisture']; ?> </td> <td width= "105" ><?php echo $row_sql['Hardiness']; ?></td> <td width= "101" ><?php echo $row_sql['Light']; ?></td> <td width= "126" ><?php echo $row_sql['HarvestInDays']; ?></td> <td width= "204" ><?php echo "<img src=".$row_sql['Image']." height =\"60\" width=\"80\">"; ?></td> </tr> </table> <?php } while ($row_sql = mysql_fetch_assoc($sql)); ?> <table border="0" width="50%" align="center"> <tr> <td width="23%" align="center"><strong> <?php if ($pageNum_sql > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_sql=%d%s", $currentPage, 0, $queryString_sql); ?>">First</a> <?php } // Show if not first page ?> </strong></td> <td width="31%" align="center"><strong> <?php if ($pageNum_sql > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_sql=%d%s", $currentPage, max(0, $pageNum_sql - 1), $queryString_sql); ?>">Previous</a> <?php } // Show if not first page ?> </strong></td> <td width="23%" align="center"><strong> <?php if ($pageNum_sql < $totalPages_sql) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_sql=%d%s", $currentPage, min($totalPages_sql, $pageNum_sql + 1), $queryString_sql); ?>">Next</a> <?php } // Show if not last page ?> </strong></td> <td width="23%" align="center"><strong> <?php if ($pageNum_sql < $totalPages_sql) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_sql=%d%s", $currentPage, $totalPages_sql, $queryString_sql); ?>">Last</a> <?php } // Show if not last page ?> </strong></td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/172484-fresh-eyes/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.