Website Scripts And Cloud Tutorials

Database Connection Pagination PHP Using Symfony Framework

Byadmin

Sep 16, 2008 , ,

Last updated on May 10th, 2016 at 12:56 am

Click to rate this tutorial!
[Total: 2 Average: 2.5]

Database Connection Pagination PHP Using Symfony Framework

After creating the project then the application and at last the module we want using symfony framework.Go to the module folder(HERE MY MODULE NAME IS PLAYLIST)

Also check out this great tutorial on how to paginate using PHP MySQL?
we will have the action.class.php and indexSuccess.php

First Take The Action.class.php file in dreamweaver or any editor you want and add the following codes

HERE PLAYLIST IS THE NAME OF MY MODULE

< ?php
class playlistActions extends sfActions
{
public function executeIndex(){//FTYPE is the table name//Audio Filed Name

//We are then itializing the pager to the criteria c

//We are going to display 10 results per page

$c = new Criteria();
$c->add(FilePeer::FTYPE,'AUDIO');
$c->add(FilePeer::USERID,0,Criteria::GREATER_THAN);
$this->data = FilePeer::doSelect($c);
//another criteria

$pager = new sfPropelPager('File',10);
$pager->setCriteria($c);
$pager->setPage($this->getRequestParameter('page', 1));

$pager->init();
$this->pager = $pager;

}
}

?>

Now we are going to use the success page of the action page indexSuccess.php

 <body bgcolor="#000000?>
< ?php use_helper('Javascript') ?><table border="1?>
< ?php $i=($pager->getPage()*10)-10+1; ?>
< ?php foreach ($pager->getResults() as $user): ?>< ?php // echo $dat->getId();

$image = $user->getUserid();

$author = $user->getCaption();
$date =$user->getDate();
$mainid =$user->getId();

?>
< ?php
//echo link_to(image_tag('http://s3.amazonaws.com/mobusers/100×100/'.$image), 'article/read?title=Finance_in_France') ?>

<td align=left><tr align=left>
<td width='1%'><input type='checkbox' name='mob$balu' id='box' value='$mainid' /><img alt='Select This Song' width=90 src='http://s3.amazonaws.com/tutorialz/100×100/<?php echo $image;?/>' ></td>
<td>
<b> <font color=#000000>< ?php echo $author;?></font></b>
<div class='desc'><i>Page: < ?php echo $image?></i></div>
<span class='postdetails'>Date Added:< ?php echo $date;?><br /><a href='javascript:void(0)' onClick="window.open('http://audio.balu.in/audio/player.php?id=<?php echo $mainid ;?>','mobplayer','height=226, width=555,toolbar=no,scrollbars=no,menubar=no,location=no,status=0,resizable=0,left=400,top=400' )">

< ?php echo image_tag('play.jpg');?> </a></span>

</td></tr></td></table>

<table border="1">

< ?php $i=$i+1; ?>
< ?php endforeach ?>

< ?php if ($pager->haveToPaginate()): ?>
</table><table width="61%" border="0? cellpadding="0? cellspacing="0?>
<tr>
<td width="10%" height="24? align="center" valign="middle" class="formText"><a href="<?php echo url_for('playlist/index?page='.$pager->getFirstPage()); ?>" class="Heading6?>FIRST</a></td>
<td width="8%" height="24? align="center" class="formText"><strong><a href="<?php echo url_for('playlist/index?page='.$pager->getPreviousPage()); ?>" class="Heading6?>< </a></a></strong></td>

< ?php $links = $pager->getLinks(); foreach ($links as $page): ?>
<td width="9%" align="center" valign="middle" class="formText">< ?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'playlist/index?page='.$page) ?>
</td>
< ?php endforeach ?>

<td width="13%" height="24? align="center" valign="middle" class="formText"><a href="<?php echo url_for('playlist/index?page='.$pager->getNextPage()); ?>">></a></td>
<td width="18%" height="24? align="center" valign="middle" class="formText"><a href="<?php echo url_for('playlist/index?page='.$pager->getLastPage()); ?>" class="Heading6?>LAST</a></td>
</tr>
</table>
< ?php endif ?>
Click to rate this tutorial!
[Total: 2 Average: 2.5]

Leave a Reply

Your email address will not be published.