Foutmelding Pagination

Status
Niet open voor verdere reacties.

tsedney

Gebruiker
Lid geworden
2 jun 2008
Berichten
42
Dit is het script.. Het is een page flipper.
Ik blijf echter maar deze foutmelding krijgen: :confused:

Parse error: syntax error, unexpected $end in C:\wamp\www\pageflipper\pagination.php on line 113



PHP:
<?php

$link = mysql_connect('localhost','root')
           or die("Error connecting to Database: " . mysql_error());

mysql_select_db('user_result') or
               die("Error Selecting Database: " . mysql_error());

//**EDIT TO YOUR TABLE NAME, ETC.

$t = mysql_query("SELECT count(*) FROM 'result' as cnt'"); 


if(!$t){
       die("Error quering the Database: " . mysql_error());
}
   
$a = mysql_fetch_object($t);
$total_items = $a->cnt;

echo "Total Number of records in Database: ".$total_items;

$limit= $_GET['limit'];
$page= $_GET['page'];

//Set default if: $limit is empty, non numerical,

//less than 10, greater than 50

if((!$limit)  || (is_numeric($limit) == false)
            || ($limit < 10) || ($limit > 50)) {
     $limit = 10; //default
}

//Set default if: $page is empty, non numerical,
//less than zero, greater than total available

if((!$page) || (is_numeric($page) == false)
         || ($page < 0) || ($page > $total_items)) {
      $page = 1; //default
}

//calculate total pages

$total_pages     = ceil($total_items / $limit);
$set_limit          = $page * $limit - ($limit);

//query: **EDIT TO YOUR TABLE NAME, ETC.

$q = mysql_query("SELECT * FROM 'result'
                                     LIMIT $set_limit, $limit");

if(!$q) die(mysql_error());

$no_row = mysql_num_rows($q);

if($no_row == 0) die("No matches met your criteria.");

//Results per page: **EDIT LINK PATH**

 echo("  
 <a href=http://localhost/pageflipper/pagination.php?limit=10&page=1>
 10</a> |
 <a href=http://localhost/pageflipper/pagination.php?limit=25&page=1>
  25</a> |
 <a href=http://localhost/pageflipper/pagination.php?limit=50&page=1>
  50</a>
");

//show data matching query:

while($code = mysql_fetch_object($q)) {

  //print your data here. 

  echo("————————————–");
  echo("Name: ".$code->user_name."<BR/>");   
  echo("Math Marks: ".$code->math_marks."<BR/>");
  echo("Physics Marks: ".$code->phy_marks."<BR/>");
  echo("————————————–");

}

//prev. page: **EDIT LINK PATH**

$prev_page = $page - 1;

if($prev_page >= 1) {
  echo("<b><<</b> <a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$prev_page>
<b>Prev.</b></a>");
}

//Display middle pages: **EDIT LINK PATH**

for($a = 1; $a <= $total_pages; $a++)
{
   if($a == $page) {
      echo("<b> $a</b> | ); //no link
     }
  else {
       echo('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$a> $a </a> | ');
     }
}

Next page: **EDIT THIS LINK PATH**

$next_page = $page + 1;
if($next_page <= $total_pages)
{
   echo  ('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$next_page><b>Next</b> > </a>');

}
?>
 
De fout zit hier in (Je kunt het al zien door de kleuren)
PHP:
//Display middle pages: **EDIT LINK PATH** 

for($a = 1; $a <= $total_pages; $a++) 
{ 
   if($a == $page) { 
      echo("<b> $a</b> | ); //no link 
     } 
  else { 
       echo('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$a> $a </a> | '); 
     } 
} 

Next page: **EDIT THIS LINK PATH** 

$next_page = $page + 1; 
if($next_page <= $total_pages) 
{ 
   echo  ('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$next_page><b>Next</b> > </a>'); 

} 
?>

Dit lijkt er meer op
PHP:
//Display middle pages: **EDIT LINK PATH** 

for($a = 1; $a <= $total_pages; $a++) {
  if($a == $page) { 
    echo("<b> $a</b> |"); //no link 
  } else {
    echo('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$a> $a </a> | '); 
  } 
} 

// Next page: **EDIT THIS LINK PATH** 

$next_page = $page + 1; 
if($next_page <= $total_pages) {
  echo  ('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$next_page><b>Next</b> > </a>');
} 
?>
 
Bedankt voor het antwoorden.
Ik heb het aangepast. Maar ik heb nu deze foutmelding:

Error quering the Database: 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 ''result' as cnt'' at line 1
 
Die fout komt door een verkeerde query. Het AS cnt zorgt voor de foutmelding.

Daarnaast kun je makkelijker gebruik maken van de functie mysql_num_rows()

Deze regels
PHP:
$t = mysql_query("SELECT count(*) FROM 'result' as cnt'");  


if(!$t){ 
       die("Error quering the Database: " . mysql_error()); 
} 
    
$a = mysql_fetch_object($t); 
$total_items = $a->cnt;
Worden dan
PHP:
$t = mysql_query("SELECT * FROM 'result'") or die("Error quering the Database: ". mysql_error());
$total_items = mysql_num_rows($t);
 
Daarnaast kun je makkelijker gebruik maken van de functie mysql_num_rows()

Makkelijker: ja.
Goedkoper: nee.
Mysql_num_rows doorloopt alle teruggegeven data en houdt dus zelf een tellertje bij. Dit is duurder dan COUNT(*).

Stel je eens voor dat je een tabel met 1.000.000 records hebt. De data die COUNT(*) teruggeeft is aanzienlijk minder dan SELECT *.

Dan moet je een keuze maken: ga ik voor gemak (SELECT * en mysql_num_rows()) of voor de "efficientere" manier (COUNT(*)).
 
Thanks.. :thumb: Ik heb de code aangepast
ik krijg nu echter deze foutmelding: :(

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 ''result' LIMIT 0, 10' at line 1
 
Je tabelnaam (result) heb je met gewone quotes omsloten ('). Dit moeten óf backticks zijn (`) óf geen quotes.

Je query wordt dan:
PHP:
$result = mysql_query("SELECT * FROM `result`") or die(mysql_error());
of
PHP:
$result = mysql_query("SELECT * FROM result") or die(mysql_error());
 
Laatst bewerkt:
Daar was ik al achter.... ik blijf deze foutmelding krijgen. Hier bij de code die ik nu heb.....


PHP:
<?php

$link = mysql_connect('localhost','root')
           or die("Error connecting to Database: " . mysql_error());

mysql_select_db('user_result') or
               die("Error Selecting Database: " . mysql_error());

//**EDIT TO YOUR TABLE NAME, ETC.

$t = mysql_query("SELECT * FROM result") or die("Error quering the Database: ". mysql_error());
$total_items = mysql_num_rows($t); 

$limit= $_GET['limit'];
$page= $_GET['page'];

//Set default if: $limit is empty, non numerical,

//less than 10, greater than 50

if((!$limit)  || (is_numeric($limit) == false)
            || ($limit < 10) || ($limit > 50)) {
     $limit = 10; //default
}

//Set default if: $page is empty, non numerical,
//less than zero, greater than total available

if((!$page) || (is_numeric($page) == false)
         || ($page < 0) || ($page > $total_items)) {
      $page = 1; //default
}

//calculate total pages

$total_pages     = ceil($total_items / $limit);
$set_limit          = $page * $limit - ($limit);

//query: **EDIT TO YOUR TABLE NAME, ETC.

$q = mysql_query("SELECT * FROM 'result'
                                     LIMIT $set_limit, $limit");

if(!$q) die(mysql_error());

$no_row = mysql_num_rows($q);

if($no_row == 0) die("No matches met your criteria.");

//Results per page: **EDIT LINK PATH**

 echo("  
 <a href=http://localhost/pageflipper/pagination.php?limit=10&page=1>
 10</a> |
 <a href=http://localhost/pageflipper/pagination.php?limit=25&page=1>
  25</a> |
 <a href=http://localhost/pageflipper/pagination.php?limit=50&page=1>
  50</a>
");

//show data matching query:

while($code = mysql_fetch_object($q)) {

  //print your data here. 

  echo("————————————–");
  echo("Name: ".$code->user_name."<BR/>");   
  echo("Math Marks: ".$code->math_marks."<BR/>");
  echo("Physics Marks: ".$code->phy_marks."<BR/>");
  echo("————————————–");

}

//prev. page: **EDIT LINK PATH**

$prev_page = $page - 1;

if($prev_page >= 1) {
  echo("<b><<</b> <a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$prev_page>
<b>Prev.</b></a>");
}

//Display middle pages: **EDIT LINK PATH** 

for($a = 1; $a <= $total_pages; $a++) {
  if($a == $page) { 
    echo("<b> $a</b> |"); //no link 
  } else {
    echo('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$a> $a </a> | '); 
  } 
} 

// Next page: **EDIT THIS LINK PATH** 

$next_page = $page + 1; 
if($next_page <= $total_pages) {
  echo  ('<a href=http://localhost/pageflipper/pagination.php?limit=$limit&page=$next_page><b>Next</b> > </a>');
} 
?>
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan