...

View Full Version : anybody help me with this php



bijaybd
03-19-2010, 03:45 AM
i have tried but failed.The buddylist shows all the buddies but i want to make it every page it will show 10 buddies only.I have both of the code but cant combine it properly so if there is anyone who can help me out will be so greatfull for me.





THE BUDDYLIST CODE:




$q = @mysql_query("select * from `buddylist` where `test`='".$user['login']."' and ci='".$ci."' and agreed='".$p."';");
while($man = @mysql_fetch_array($q)) {

$rs = @mysql_query("select * from `chat_users` where login='".$man['name']."' and `ltime`>'".intval(time()-$offline)."';");
$d = @mysql_fetch_array($rs);

echo "".$man['name'].",
<a href=\"./user.php?".SID."&amp;nocache=$nocache&amp;room=$room&amp;m=$n&amp;dblogin=".$man['name']."\">Pm</a>";





if ($d=="") { echo " Offline<br/>"; } else { echo " <b>Online</b><br/>"; } }



THE 10 PERSONS SHOWS EVERY PAGE CODE


if($page=="" || $page<=0)$page=1;
$noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM kitkat"));
$num_items = $noi[0];
$items_per_page= 10;
$num_pages = ceil($num_items/$items_per_page);
if(($page>$num_pages)&&$page!=1)$page= $num_pages;
$limit_start = ($page-1)*$items_per_page;

//changable sql

$sql = "SELECT abc, ads, pnd FROM kitkat ORDER BY id DESC LIMIT $limit_start, $items_per_page";
$items = mysql_query($sql);

echo mysql_error();
if(mysql_num_rows($items)>0)
{
while ($item = mysql_fetch_array($items))
{

echo "$item[1] &#187; ";
echo "<img src=\"$item[2]\" alt=\"$item[1]\"/><br/>";
}
}
if($page>1)
{
$ppage = $page-1;
echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$ppage\">&#171;PREV</a> ";
}
if($page<$num_pages)
{
$npage = $page+1;
echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$npage\">Next&#187;</a>";
}
echo "<br/>$page/$num_pages<br/>";




ALL I WANT IS THAT THE 1ST PAGE LIST WILL BE LIKE THE SECOND PAGE 10 PERSONS SHOWS EVERY PAGE.

masterofollies
03-19-2010, 05:06 AM
What this is called is Pagination. It's quite complex in my opinion.

http://www.phpfreaks.com/tutorial/basic-pagination

bijaybd
03-19-2010, 06:43 PM
can anybody do it for me please it will be so greatful i tried a lot of times but i failed

masterofollies
03-19-2010, 09:26 PM
It'd be very rare to find someone to do this for you for free, because it can take quite a long time to do, by studying your own and putting it in.

You may can hire someone for $20 in the work forums to do it.

bijaybd
03-19-2010, 09:46 PM
i guess just need to put the sql queries in the right place where i am failing to do i just need a page with every page 10 buddies will show i also even given the buddylist code sql queries just need to be putten those quries in the 2nd page i have given for the list

masterofollies
03-19-2010, 11:32 PM
It's super easy to display 10 records, but when you get into auto creating pages, that is the hard part.

If you know exactly how many records you will have total, you can setup your own pages the way you want them.

bijaybd
03-20-2010, 12:46 AM
if($page=="" || $page<=0)$page=1;
$noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM kitkat"));
$num_items = $noi[0];
$items_per_page= 10;
$num_pages = ceil($num_items/$items_per_page);
if(($page>$num_pages)&&$page!=1)$page= $num_pages;
$limit_start = ($page-1)*$items_per_page;

//changable sql

$sql = "SELECT abc, ads, pnd FROM kitkat ORDER BY id DESC LIMIT $limit_start, $items_per_page";
$items = mysql_query($sql);

echo mysql_error();
if(mysql_num_rows($items)>0)
{
while ($item = mysql_fetch_array($items))
{

echo "$item[1] » ";
echo "<img src=\"$item[2]\" alt=\"$item[1]\"/><br/>";
}
}
if($page>1)
{
$ppage = $page-1;
echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$ppage\">«PREV</a> ";
}
if($page<$num_pages)
{
$npage = $page+1;
echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$npage\">Next»</a>";
}
echo "<br/>$page/$num_pages<br/>";



This one is the system to show 10 records each time and next page will be the same page just page will be $npage thats all i want i just need to put the sql queries in this codes perfectly then it will work i hope so please help me .


and sorry for my bad english i know it will be hard for everyone 2 understand



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum