Jump to content


Photo

how to paginate this??


  • Please log in to reply
22 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 07:42 AM

i have this little script to view all user friends.. and i want to limit it to about 5 per-page so my page doesnt scroll down a long way.. how would i add pagination??

<?php
$user = $_SESSION[username];
$query = mysql_query("SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes'");
while ($array = mysql_fetch_array($query)){
$to=$array['friend'];
echo "<br><center><b>" .$to. "</b></center>";
echo "<a href='sendMessage.php?to=" .$to. "'>-Message " .$to. "-</a> |<a href='getInfo.php?user=" .$to."'> -Get Info-</a> | <a href='http://zycoworld.com/" .$to. "'>-View zPage-</a><br><form action=\"\" method=\"post\">
      <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"delete\" value=\"-Remove-\"></td></tr><input type=\"hidden\" name=\"friend\" value=\"$to\">
</table>
</form>";
}
?>

Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 07:55 AM

just set this
$max_results = 1;

example only not tested ok.

good luck.
<?php session_start();

$user = $_SESSION[username];

if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

$max_results = 1; 


$from = (($page * $max_results) - $max_results); 

$query="SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes LIMIT $from, $max_results";


while ($array = mysql_fetch_assoc($query)){
$to=$array['friend'];


echo "<br><center><b>" .$to. "</b></center>";
echo "<a href='sendMessage.php?to=" .$to. "'>-Message " .$to. "-</a> |<a href='getInfo.php?user=" .$to."'> -Get Info-</a> | <a href='http://zycoworld.com/" .$to. "'>-View zPage-</a><br><form action=\"\" method=\"post\">
      <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"delete\" value=\"-Remove-\"></td></tr><input type=\"hidden\" name=\"friend\" value=\"$to\">
</table>
</form>";

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM friends where `username` = '$user'"),0); 

$total_pages = ceil($total_results / $max_results); 

if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; 
 } 
for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 

if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";

} 

 }
?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 08:03 AM

i got this :

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/zycoworld.flamelicker.com/newlayout/index.php on line 104"



Link shortener with advanced, detailed statistics:

http://tyny.us/

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:05 AM

this
$query="SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes LIMIT $from, $max_results";

to this

$query="SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes' LIMIT $from, $max_results";

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 08:08 AM

tried it ... :-P i saw u were missing the ' after 'yes
Link shortener with advanced, detailed statistics:

http://tyny.us/

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:11 AM

from
while ($array = mysql_fetch_assoc($query)){
to
while ($array = mysql_fetch_array($query)){


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 08:17 AM

i got the same error again.. heres line 93 - 117

if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

$max_results = 1; 


$from = (($page * $max_results) - $max_results); 

(LINE 104) $query="SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes LIMIT $from, $max_results";


while ($array = mysql_fetch_array($query)){
$to=$array['friend'];


echo "<br><center><b>" .$to. "</b></center>";
echo "<a href='sendMessage.php?to=" .$to. "'>-Message " .$to. "-</a> |<a href='getInfo.php?user=" .$to."'> -Get Info-</a> | <a href='http://zycoworld.com/" .$to. "'>-View zPage-</a><br><form action=\"\" method=\"post\">
      <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"delete\" value=\"-Remove-\"></td></tr><input type=\"hidden\" name=\"friend\" value=\"$to\">
</table>
</form>";

line 104 is the line mysql said was giving me probs ...
Link shortener with advanced, detailed statistics:

http://tyny.us/

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:21 AM

try this for one min
$query="SELECT * FROM friends WHERE `username` = '$user' LIMIT $from, $max_results";

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 08:27 AM

i got the same error.. again. hmm what could be wrong?
Link shortener with advanced, detailed statistics:

http://tyny.us/

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:27 AM

trie this ok.
<?php session_start();

$user = $_SESSION[username];

if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

$max_results = 1; 


$from = (($page * $max_results) - $max_results); 

$query="SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes' LIMIT $from, $max_results";

$result=mysql_query($query);

while($array=mysql_fetch_assoc($result)){

$to=$array['friend'];


echo "<br><center><b>" .$to. "</b></center>";
echo "<a href='sendMessage.php?to=" .$to. "'>-Message " .$to. "-</a> |<a href='getInfo.php?user=" .$to."'> -Get Info-</a> | <a href='http://zycoworld.com/" .$to. "'>-View zPage-</a><br><form action=\"\" method=\"post\">
      <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"delete\" value=\"-Remove-\"></td></tr><input type=\"hidden\" name=\"friend\" value=\"$to\">
</table>
</form>";

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM friends where `username` = '$user'and `accepted` = 'yes'"),0); 

$total_pages = ceil($total_results / $max_results); 

if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; 
 } 
for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 

if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";

} 

 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 08:33 AM

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/zycoworld.flamelicker.com/newlayout/index.php on line 104"

same error.. on the same line... again
Link shortener with advanced, detailed statistics:

http://tyny.us/

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:34 AM

$query="SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes' LIMIT $from, $max_results";

$result=mysql_query($query);

while($array=mysql_fetch_assoc($result)){
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:39 AM

heres one i just made and works fine.

<?php session_start();

$db=mysql_connect("localhost" , "xxx" , "xxxx");
mysql_select_db("promotor",$db);

?>


<html>
<head>
<title>Send Message</title>
<body bgcolor="#A0C0F0">
<br><br><br><br><br>



<?php



if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

$max_results = 1; 


$from = (($page * $max_results) - $max_results); 

$query="select * from member_messages where id='$id' LIMIT $from, $max_results";


$result=mysql_query($query);
while($record=mysql_fetch_assoc($result)){


echo"<table align='center' width='300'border='4' bordercolor='black'><td align='left'><b>Members Id:<font color='red'><br>".$record["sent_id"]."</font><br> User Name: <font color='red'><br>".$record["members_name"]."</font><br>
Sent Time: <font color='red'><br>".$record["time"]."</font> <br> Sent Date <font color='red'><br>".$record["date"]."</font> </b></td><td align='center' valign='top'><b>Members Message <font color='red'>$page</font><b>
<br><br><b><div align='left'><textarea col='7' rows='7'style='color: white; background-color: #A0C0F0'>".$record["message"]."</textarea></td></b></div><table>";





echo "<table align='center' width='300'border='4' bordercolor='black'><td align='center'><b>";


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM member_messages where id='$id'"),0); 


$total_pages = ceil($total_results / $max_results); 


echo "<center><b>Select A Message!</b><br>"; 


if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 


if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";

} 


echo "</center>"; 
echo'</td></table>';

echo "<table align='center' width='300'border='4' bordercolor='black'><td align='center'><b>Send A Reply    <font color='red'><a href='reply_message.php?&id=".$record['sent_id']."'>Reply</a></b></font>
<font color='red'><a href='delete_message.php?&cmd=delete&time=".$record['time']."&id=".$record['sent_id']."'>Delete</a></b></font>
</td></table><br>";
}

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 08:40 AM

well those 3 fixes you posted worked!!
Link shortener with advanced, detailed statistics:

http://tyny.us/

#15 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:41 AM

good happy now
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#16 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 08 September 2006 - 08:58 AM

redarrow - it's
$_SESSION['username']
not
$_SESSION[username]


#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 09:00 AM

i didnt write that code so tell the designer ok sorry i only inplemented the rest.

if you look at the first post your notice that and i totaly agree, i can not sit here doing all the work for the user can i.

dont no why your pointing this out as all i do is help others but thank you i pm the user and tell them ok.

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 08 September 2006 - 09:08 AM

don't tak offence... I merely corrected a mistake..

#19 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 08 September 2006 - 09:09 AM

i think .. i made him mad.. idk how.. :-(
Link shortener with advanced, detailed statistics:

http://tyny.us/

#20 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 08 September 2006 - 09:17 AM

still experiencing problems?

echo all your queries to see if they are 'correct'




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users