Subject: | Thats a good and useful class !!... |
Summary: | Package rating comment |
Messages: | 10 |
Author: | José Filipe Lopes Santos |
Date: | 2008-06-20 10:26:50 |
Update: | 2008-06-23 10:38:32 |
|
|
|
José Filipe Lopes Santos rated this package as follows:
Utility: | Good |
Consistency: | Good |
Examples: | Good |
|
José Filipe Lopes Santos - 2008-06-20 10:26:50
Thats a good and useful class !! lool
I use pagination, to show records from oracle databade ... !! lol
Steve Barbera - 2008-06-20 12:53:38 - In reply to message 1 from José Filipe Lopes Santos
Thanks for this class! I have had the hardest time working with MSSQL Pagination. This will make my applications a breeze now! I have one question though does anyone have a good tutorial on making the page links use the ... in the middle? Like this:
1 | 2 | 3 | 4 |...| 20
Thanks for the help!
Steve Barbera - 2008-06-20 13:56:31 - In reply to message 2 from Steve Barbera
I have one more question about this Pagination. Im not the greatest with PHP, but I know what I want in order to output the correct results on my page. What I'm looking to do is to fetch the array from the mssql query.
So that when I fetch my array I can write a statement like:
while($result){
foreach($result as $varname=>$value){
$$varname = $value;
}
echo $name1;
echo $name 2;
}
But with this script its giving it to me with no variable names. What do I need to modify in the Class in order to change the output to what i'm looking for? I tried playing around with the mssql_fetch_row, but that still doesn't give me the result i'm looking for.
Any suggestions would be awesome! Thank you!
Fahad Waheed Khan - 2008-06-20 19:40:06 - In reply to message 3 from Steve Barbera
Hi Steve,
I will try answer your question very soon.
Steve Barbera - 2008-06-20 19:56:58 - In reply to message 4 from Fahad Waheed Khan
Hi Fahad,
I actually figured it all out! alot of trial and error but I figured it out.
The way I was able to assign the variable names to the values was doing this:
foreach($result as $varname => $value){
foreach($value as $varname2 => $value2){
$$varname2 = $value2;
}
$name1;
$name2;
}
I was using the while statement before but that didn't work out. Foreach works much better!
AS for the pagination problem at the end I added a little script at the end to figure out the remaining number of entries on the last page and subtract that from the num_per_page, and loop based on that. Here is the code I used for that.
function get_page_result() {
if( $this->set_page() != 0 ){
$this->seek = $this->set_page() * $this->num_per_page;
//$seek++;
}
$total_row = $this->get_total_rows();
$total_page = $this->get_num_pages() * $this->num_per_page;
$total_max = ($total_page - $total_row);
$remainder = $this->num_per_page - $total_max;
$current_page = $this->set_page() +1;
$this->result = mssql_query($this->sql);
mssql_data_seek($this->result, $this->seek);
//return $this->result;
if($current_page == $this->get_num_pages()){
for($rv=1; $rv<=$remainder; $rv++){
$row=mssql_fetch_array($this->result);
$returnarray[]=$row;
}
}else{
for($rv=1; $rv<=$this->num_per_page; $rv++){
$row=mssql_fetch_array($this->result);
$returnarray[]=$row;
}
//echo "{$row[0]}-{$row[1]}<br>";
}
return $returnarray;
}
Steve Barbera - 2008-06-20 19:59:17 - In reply to message 5 from Steve Barbera
Sorry I had one more thing to say.
I really appreciate you writing this script and its been a great project to integrate it into my site. The code i'm using to do pagination has been cleaned up a ton!
The one thing I'm unsure about is the pagination with the '...' in between the first 5 and the last page. example:
1 | 2 | 3 | 4 | ... | 20 |
I'm not sure how to do that. Other than that I appreciate the script!
Fahad Waheed Khan - 2008-06-21 09:48:57 - In reply to message 5 from Steve Barbera
You can include this method in the class definition if you like to retrieve field names from the query.
function get_field_names(){
while($fld = mssql_fetch_field($this->result)){
$FieldNames[]=$fld->name;
}
return $FieldNames;
}
Fahad Waheed Khan - 2008-06-21 10:41:30 - In reply to message 6 from Steve Barbera
Steve thanks for appreciating my script. Please tell me how would u like to display navigation on other pages other than the First Page.
On First Page we display this.
1 | 2 | 3 | 4 | ... | 20 |
but if we or on Page 8 how would u like to display navigation there ?
Steve Barbera - 2008-06-21 13:06:22 - In reply to message 8 from Fahad Waheed Khan
Ideally It would display the first 3 pages and the last 3 pages? Kind of like how google does it? That would be the best deal so if you are on page it it would be :
... 5 | 6 | 7 | 8 | 9 | 10 | 11...
José Filipe Lopes Santos - 2008-06-23 10:38:32 - In reply to message 9 from Steve Barbera
Hi !!
I think that a better choise is to select any results, not all
example: select * from table limit 10 (list 10 results)
But, better of this, and for uniformization in databases, i recomend that use the package DB of the pear
pear.php.net/manual/en/package.data ...
Advantage: if past time you change your database from mysql to oracle, or to postgresql, ..., you dont need change all the code, but something change one string called DSN ... !!
This is so mutch fine, and im working so many time with this package !!
And for pagination, it has a function called limitquery(select,posini,numrows)
where posini is the inicial position of the page, and numrows the number of the rows by page
Example:
numrows = 15
Page 1: limitquery(select,0,15) // records from the 0 to 14 positions
Page 2: limitquery(select,15,15)
....
|