Gem Posted March 29, 2009 Share Posted March 29, 2009 Hiya .. I'm getting an error but I dont know why. This code works on another page and all I did was change the names of the table and columns?! Any ideas?? The table is sn_articles and columns: sn_id, sn_title, sn_subtitle, sn_article. Thanks <?php // database connection info $conn = mysql_connect(" =) ") or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM sn_articles"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 1; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT sn_title, sn_subtitle, sn_article FROM sn_articles ORDER BY ID DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data ?><H2><?php echo nl2br($list['sn_title']); ?> </H2> <H3><?php echo nl2br($list['sn_subtitle']); ?> </H3> <?php echo nl2br($list['sn_article']); echo "<br />##########################################"; echo "<br /><br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 4; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?> Error: PHP Fatal error: SQL in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\specialneeds\news.php on line 189 I think line 189 is: // get the info from the db $sql = "SELECT sn_title, sn_subtitle, sn_article FROM sn_articles ORDER BY ID DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); Link to comment https://forums.phpfreaks.com/topic/151625-solved-fatal-error/ Share on other sites More sharing options...
wildteen88 Posted March 29, 2009 Share Posted March 29, 2009 Your query is failing. Change this $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); to $result = mysql_query($sql, $conn) or trigger_error("SQL Error: ".mysql_error(), E_USER_ERROR); Link to comment https://forums.phpfreaks.com/topic/151625-solved-fatal-error/#findComment-796314 Share on other sites More sharing options...
Gem Posted March 29, 2009 Author Share Posted March 29, 2009 Thank you - new error: PHP Fatal error: SQL Error: Unknown column 'ID' in 'order clause' in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\specialneeds\news.php on line 189 Link to comment https://forums.phpfreaks.com/topic/151625-solved-fatal-error/#findComment-796317 Share on other sites More sharing options...
wildteen88 Posted March 29, 2009 Share Posted March 29, 2009 MySQL cannot find the column ID within your sn_articles table. You made sure you're using the correct column Link to comment https://forums.phpfreaks.com/topic/151625-solved-fatal-error/#findComment-796318 Share on other sites More sharing options...
Gem Posted March 29, 2009 Author Share Posted March 29, 2009 oh yeh i see the problem lol ... its the ORDER BY id .. the column is sn_id Thanks Mate xxx Link to comment https://forums.phpfreaks.com/topic/151625-solved-fatal-error/#findComment-796322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.