Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/06/2011, 09:39
smart22000
 
Fecha de Ingreso: diciembre-2010
Mensajes: 3
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: php sobre paradox

intenta con este codigo tienes que cambiar varios paramentros

<?php
$dsn="pad";
$user=" ";
$pass=" ";
//connecting to the database using ODBC

$db = odbc_connect ( $dsn , $user , $pass )or die( "Error: Can't Connect to Database" );

// assigns a value how many rows we will get from each page
$limit = 15 ;

/* assign variable with sql query of counting how many rows are there in the database.
take note you should assign * with a table data name and table_name with table name*/
$query_count = "SELECT COUNT (*) as value FROM BLKBRD " ;

//executes the sql statement to the database
$result_count = odbc_exec ( $db , $query_count );

// get the result count from the database
$totalrows = odbc_fetch_object ( $result_count );

if(empty( $page )){ // Checks if the $page variable is empty (not set)
$page = 1 ; // If it is empty, we're on page 1
}

//this will be the lowest limit
$limitvalue = $page * $limit - ( $limit );
$limitnew = $limitvalue + $limit ;
// Ex: (2 * 25) - 25 = 25 <- data starts at 25
$query = "SELECT * FROM table_name where ID between $limitvalue and $limitnew ORDER BY ID ASC" ;

//executes the sql statement to the database
$result = odbc_exec ( $db , $query );

echo "<table><tr><td>Title1</td>
<td>Title2</td>" ;

// open loop to list down contents from the database
while (( $row = odbc_fetch_object ( $result ))) {

echo "<tr><td> $row -> content_title1 </td>
<td> $row -> content_title2 </td>" ;

//close the loop
}

//now we close the table
echo "</table>" ;

/*check if we are at page 1. if true, PREV will not be a link. if false, $page will be a link minus 1 page. */
if( $page != 1 ){
$pageprev = $page - 1 ;
echo( "&nbsp;<b><a href=" $PHP_SELF ? page = $pageprev ">PREV</a></b>&nbsp;" );
}else{
echo( "&nbsp;PREV&nbsp;" );
}

/* $numofpages will be the quotient of the total rows divided by the limit value
in this example lets assume that we have 47 rows in the database divided by 15 will result 3.13 */
$numofpages = $totalrows -> value / $limit ;

/* now let us generate those page numbers*/
for( $i = 1 ; $i <= $numofpages ; ++ $i ){
if( $i == $page ){
echo( "&nbsp;[ $i ]&nbsp;" );
}else{
echo( "&nbsp;<b><a href=" $PHP_SELF ? page = $i "> $i </a></b>&nbsp;" );
}
}

/* check if we have a remainder and print it at the end page list */
if(( $totalrows -> increm % $limit ) != 0 ){
if( $i == $page ){
echo( "&nbsp;[ $i ]&nbsp;" );
}else{
echo( "&nbsp;<b><a href=" $PHP_SELF ? page = $i "> $i </a></b>&nbsp;" );
}
}

/* finally we check the "next" link if we have a page to move on to, if yes we put it as a link adding another page.
in this example assuming that we have $totalrows->value=47
this will check if (47 - (15 * 1) = 32) > zero, results to true will give a link.*/
if(( $totalrows -> value - ( $limit * $page )) > 0 ){
$pagenext = $page + 1 ;

echo( "&nbsp;<b><a href=" $PHP_SELF ? page = $pagenext ">NEXT</a></b> " );
}else{
echo( "&nbsp;NEXT&nbsp;" );
}

// now let us free the resources
odbc_free_result ( $result );

?>