Jump to content


Photo

Pagination....


  • Please log in to reply
1 reply to this topic

#1 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 07 April 2006 - 07:13 PM

I am trying to get help with this pagination program, I don't know what to do about getting an error message stating: "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0, 25' at line 2". I don't see the problem with my script. Any ideas?

php:
<?php

@mysql_connect(mysql, , ) or die("ERROR--CAN'T CONNECT TO SERVER");
@mysql_select_db(AUDITMED) or die("ERROR--CAN'T CONNECT TO DB");


$metode = $_REQUEST['metode'];
$search = $_REQUEST['search'];
$metode2 = $_REQUEST['metode2'];
$search2 = $_REQUEST['search2'];


$limit = 25;
$query_count = "SELECT count(*) FROM AUDIT";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

if(empty($page)){
$page = 1;
}


$limitvalue = $page * $limit - ($limit);
$query = "SELECT `AUDIT` . `DT_STRING` , `AUDIT` . `ACCOUNT` , `AUDIT` . `ACCOUNT_TYPE` , `AUDIT` . `CLIENT_ID` , `AUDIT` . `USER_ID`
FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' ORDER BY DT_STRING $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());

if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}

$bgcolor = "#E0E0E0"; // light gray

echo("<table>");

while($row = mysql_fetch_array($result)){
if ($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}

echo("<tr bgcolor=".$bgcolor.">n<td>");
echo($row["'DT_STRING','ACCOUNT','ACCOUNT_TYPE','CLIENT_ID','USER_ID'"]);
echo("</td>n<td>");
echo($row["'DT_STRING','ACCOUNT','ACCOUNT_TYPE','CLIENT_ID','USER_ID'"]);
echo("</td>n</tr>");
}

echo("</table>");

if($page != 1){
$pageprev = $page--;

echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");
}else{
echo("PREV".$limit." ");
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}


if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}

if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;

echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
}else{
echo("NEXT".$limit);
}

mysql_free_result($result);

?>

Thanks for any help in advance!


#2 jworisek

jworisek
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 07 April 2006 - 07:47 PM

if you are trying to limit the query you need to add LIMIT to it...

it is trying to run


... ORDER BY DT_STRING 0,25"; 

// try this

... ORDER BY DT_STRING ASC LIMIT 0,25"; 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users