nathanmaxsonadil Posted July 28, 2007 Share Posted July 28, 2007 What did I do wrong here? $dbh=mysql_connect ("localhost", "my_username", "my_password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("my_db"); // how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT COUNT( * ) AS `Rows` , `stixy` FROM `emailists` GROUP BY `stixy` ORDER BY `stixy` LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Sorry the system has an error, please report this to the admin and tell them the error id is SQ87'); // print the random numbers while($row = mysql_fetch_array($result)) { echo $row['*'] . '<br>'; } echo '<br>'; // how many rows we have in database $query = "SELECT COUNT( * ) AS `Rows` , `stixy` FROM `emailists` "; $result = mysql_query($query) or die('Sorry the system has an error, please report this to the admin and tell them the error id is SQ88'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last; Link to comment https://forums.phpfreaks.com/topic/62226-solved-help/ Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 SELECT COUNT( * ) AS `Rows` , `stixy` FROM `emailists` I believe that query is incorrect as mixing of columns and special operators such as COUNT, SUM is not allowed without a GROUP BY clause. Link to comment https://forums.phpfreaks.com/topic/62226-solved-help/#findComment-309697 Share on other sites More sharing options...
nathanmaxsonadil Posted July 28, 2007 Author Share Posted July 28, 2007 How would I make it work then? Link to comment https://forums.phpfreaks.com/topic/62226-solved-help/#findComment-309701 Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 remove stixy SELECT COUNT( * ) AS `Rows` FROM `emailists` or GROUP BY stixy SELECT COUNT( * ) AS `Rows` , `stixy` FROM `emailists` GROUP BY `stixy` or perhaps separate them into two separate queries. Link to comment https://forums.phpfreaks.com/topic/62226-solved-help/#findComment-309703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.