How to break the loop for 3 values and continue

General discussions related to php

Moderators: macek, egami, gesf

knaresh
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Mar 05, 2013 11:11 pm

How to break the loop for 3 values and continue

Postby knaresh » Tue Mar 05, 2013 11:28 pm

Hi im new for the PHP. In my project having account page in that page im using while loop for retrieving the data user values.here i should show 3 values and if user clicks pagination next button then it should show next three values in same page..and if user clicks again next button and i should show next next three values...here the condition is i should show only three values per page...
<?php
$r12 = mysql_query("SELECT COUNT(*) FROM Op where Active=1 and UserID=".$uid);

$r = mysql_fetch_row($r12);
$numrows = $r[0];
$rowsperpage = 1;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if

// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
?>
<?php

$i=1; $j=0;
$sql = mysql_query("SELECT * from Op where UserID=".$uid." and Active=1 order by TimeStamp desc");

$num_rows=mysql_num_rows($sql);
if($num_rows > 0)
{
while($d=mysql_fetch_array($sql))
{
if($i==1)
{
echo "<div class='mainScroller listingPage'>";
}


?>

<div class="itemCell itemCellFix itemListing">
<div class="imgItem">
<a href="itemDetails.php?ID=<?php echo $d['O']; ?>"></a>
</div>
<h4 class="spacer"><?php $sub=$d['Sb']; ?></h4>
<span class="listQ">
Location
</span>
<span class="listA"><?php $v2=$data["Loc"];?></span>
<?php
$j++;
if($i%1==0)
{
echo "</div>";
$i=1;
continue;
}
$i++;

} if($numrows%1!=0)
{
echo "</div>";
echo"qwe";
} ?>

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to break the loop for 3 values and continue

Postby seandisanti » Wed Mar 06, 2013 2:58 pm

as we don't have data to go with the example, we need you to tell us what it's doing wrong, or what the error is for us to be able to help. Also use of [ code=PHP] [ /code] tags around code helps readability.

seoitc
New php-forum User
New php-forum User
Posts: 5
Joined: Wed Dec 12, 2012 11:11 am

Re: How to break the loop for 3 values and continue

Postby seoitc » Sat Mar 09, 2013 6:07 pm

Your article really confusing.
I do not know how to edit

viper94x
New php-forum User
New php-forum User
Posts: 15
Joined: Mon Apr 16, 2012 2:15 am
Location: Netherlands

Re: How to break the loop for 3 values and continue

Postby viper94x » Tue Mar 12, 2013 1:58 am

For building pagination scripts, I would recommend using Javascript + Jquery.
Create an array in PHP that holds all the info for all the pages.
And loop through that array in Javascript when a user clicks next.
If you need help with the code, send me a PM.

Sam


Return to “PHP General”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest