views:

128

answers:

1
+1  Q: 

MySQL fatal error

Hi,

When I run the folowing code, I get this error:

Fatal error: SQL in /Users/allan/Sites/4is_site/casestudyall.php on line 105 (that's the last line in the code below.

Is there a problem with my query?

<?php
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} 
else {
   $pageno = 1;
}   

$query = "SELECT count(*) FROM studies ORDER BY (date) desc";
$result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);



$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 4;
$lastpage      = ceil($numrows/$rows_per_page);

$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
}
if ($pageno < 1) {
   $pageno = 1;
}
?>

<div class='column3'><p class='bodygrey'>

<?php

$totalpages = ceil($numrows / $rows_per_page);

if($totalpages >= 1){ $pagelinkcount = 1;} else { $pagelinkcount = 0; }

if($totalpages > 1){ $pagelinkcount = 1;  echo 'Page ';}

while($pagelinkcount <= $totalpages && $totalpages > 1) {




     echo "<a href=\"{$_SERVER['PHP_SELF']}?pageno={$pagelinkcount}\">{$pagelinkcount}</a> ";

     $pagelinkcount++;

}
?>
</p></div></div></div>
<?php


$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM studies".
         "ORDER BY date DESC $limit";


$result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);
+8  A: 

The problem is likely with the following code:

$query = "SELECT * FROM studies".
         "ORDER BY date DESC $limit";

That will produce the following query:

SELECT * FROM studiesORDER BY date DESC $limit

Notice the missing space between "studies" and "ORDER".

William Brendel
nice catch, looked right in the first query, didn't catch that second one
Ian Elliott
You're too fast wow.
drikoda