Jump to content

Recommended Posts

I got a major brain cramp. I can't seem to organize my thoughts very much anymore lol

 

so what I am trying to do is display entries from my db using pagination.

 

First I didn't use pagination and my code looked like this:

$numrow = mysql_num_rows(mysql_query("SELECT * from `messages` WHERE (`from`='{$_SESSION['id']}' OR `to`='{$_SESSION['id']}') AND `mail_id`='$id'"));
if($numrow > 3){ $lim = $numrow-3; }else{ $lim = 0; }

$ms=mysql_query("SELECT * from `messages` WHERE (`from`='{$_SESSION['id']}' OR `to`='{$_SESSION['id']}') AND `mail_id`='$id' ORDER BY `id` ASC LIMIT $lim,3");

so that worked the way I liked it to. it would display 3 entries and the newest entry would display last.

 

now that I have pagination it displays last, but last meaning the last page. I want the newest entries on the first page but show the newest entry last but on the first page.

 

$per_page = 3; 
$page=clean_up($_GET['page']);
$id=clean_up($_GET['id']);

$start = ($page-1)*$per_page;
$ms=mysql_query("SELECT * from `messages` WHERE (`from`='{$_SESSION['id']}' OR `to`='{$_SESSION['id']}') AND `mail_id`='$id' ORDER BY `id` DESC LIMIT $start,$per_page");

Link to comment
https://forums.phpfreaks.com/topic/239922-brain-cramp/
Share on other sites

now that I have pagination it displays last, but last meaning the last page. I want the newest entries on the first page but show the newest entry last but on the first page.

what i meant was that I want to display entries and order them so the newest one is displayed last on each page there is. so the last page has the oldest entries but the oldest entry of them all should be displayed first on the last page.

 

possible?

Link to comment
https://forums.phpfreaks.com/topic/239922-brain-cramp/#findComment-1232427
Share on other sites

hmm did that..

$ms=mysql_query("SELECT * from `messages` WHERE (`from`='{$_SESSION['id']}' OR `to`='{$_SESSION['id']}') AND `mail_id`='$id' ORDER BY `id` DESC LIMIT $start,$per_page");
$rows = array_reverse($ms);
foreach ($rows as $msg){
$mamessage=clean_up($msg['message']);
$from=clean_up($msg['from']);

and it doesn't display anything..

Link to comment
https://forums.phpfreaks.com/topic/239922-brain-cramp/#findComment-1232506
Share on other sites

Ohh yeah.. sorry, I was in the middle of class :P

 

I think he meant:

$ms=mysql_query("SELECT * from `messages` WHERE (`from`='{$_SESSION['id']}' OR `to`='{$_SESSION['id']}') AND `mail_id`='$id' ORDER BY `id` DESC LIMIT $start,$per_page");
while($row = mysql_fetch_array($ms)) {
  $rows[] = $row;
}
$rows = array_reverse($rows);

Link to comment
https://forums.phpfreaks.com/topic/239922-brain-cramp/#findComment-1232515
Share on other sites

oh.. alrighty.

so where does the content go? inside the while I assume right?

so like..

 

$ms=mysql_query("SELECT * from `messages` WHERE (`from`='{$_SESSION['id']}' OR `to`='{$_SESSION['id']}') AND `mail_id`='$id' ORDER BY `id` DESC LIMIT $start,$per_page");
while($row = mysql_fetch_array($ms)) {
  $rows[] = $row;

$message=clean_up($row['message']);
$from=clean_up($row['from']);
echo "$from $message";

}
$rows = array_reverse($rows);

 

hmm maybe not.. I don't think that makes sense..

but if I put it in after the array_reverse it wouldn't display each row of data.. it would only display one, right? idkk.. im totally confused now.

 

with what I had before from gizmola spit out an error, just forgot I didn't have error reporting off so I had to turn it on. it said:

Warning: array_reverse() expects parameter 1 to be array, resource given in /var/www/satanicempire/pages/message_data.php on line 33 Warning: Invalid argument supplied for foreach() in /var/www/satanicempire/pages/message_data.php on line 34

Link to comment
https://forums.phpfreaks.com/topic/239922-brain-cramp/#findComment-1232518
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.