RealDrift Posted December 5, 2007 Author Share Posted December 5, 2007 poco i get same error still: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-4,4' at line 1 With query: SELECT * FROM goldies WHERE Receiver='WeedHunteR' LIMIT -4,4 Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 5, 2007 Share Posted December 5, 2007 I think it's because your getting a negative number (-4). Try changing $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; To <?php $first_l = ($pagenum - 1) * $page_rows; if ($first_l < 0) $max = '0, '.$page_rows; else $max = $first_l .', ' .$page_rows; ?> Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 5, 2007 Author Share Posted December 5, 2007 ok the table is echoed now, although its wide and the links are at the top of the page in the top left hand corner when i hoped they would have been under the table, the links NEXT and LAST have the right urls but when i click them the page reloads page 1 again. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 5, 2007 Share Posted December 5, 2007 damato, i changed the code you gave me and i got the following results: When i hover mouse over NEXT link i see the link in status bar for page 2 which is correct. But when i click any link it only reloads page 1. What EXACTLY is the URL when you hover over the next link? Have you tried to verify what $page is getting set to? Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 5, 2007 Author Share Posted December 5, 2007 the URL is http://127.0.0.1//game/creditshistory.php?page=2 that is the URL when i hover over the link for page 2 and when i hover over NEXT I echoed the variable $page which echoed "1" Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 5, 2007 Share Posted December 5, 2007 In your code your using "pagenum" as the page number, not "page"...so I don't even understand how your getting that as a URL. You also never define $page as $_GET['page']... Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 5, 2007 Share Posted December 5, 2007 Try this tutorial...I looked through it and it actually used $_GET, I have no idea why the other one would assume you had register_globals off. http://www.tonymarston.net/php-mysql/pagination.html Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 5, 2007 Author Share Posted December 5, 2007 poco, the script you told me to use from about.com uses pagenum, however the script me and damato were working on uses page. My earlier comment about the URL was for his script, the script me and you were looking at is: <?php //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $data = mysql_query("SELECT * FROM goldies WHERE Receiver='$username'") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 10; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $first_l = ($pagenum - 1) * $page_rows; if ($first_l < 0) $max = '0, '.$page_rows; else $max = $first_l .', ' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $data_q = "SELECT * FROM goldies WHERE Receiver='$username' LIMIT $max"; $data_p = mysql_query($data_q)or die(mysql_error().'<p>With query:<br>'.$data_q); //This is where you display your query results while($info = mysql_fetch_array( $data_p )) { echo("<tr bgcolor=".$bgcolor."><td>"); echo($info["Sender"]); echo("</td><td>"); echo($info["Amount"]); echo("</td><td>"); echo($info["Date"]); echo("</td></tr>"); } echo "<p>$page"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> This uses pagenum. This produces the table okay and everything, but when i click the links the page reloads to show page 1. The Links have the correct urls however. My earlier post mentioning urls having 'page' links was for the script i am working on with damato. Is it all clear? Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 6, 2007 Share Posted December 6, 2007 how do you want your link look like? i mean the format and functionality ... Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 basically teng the problem is, the pagination displays ok. Everything works as in the table with results is displayed. The links to different pages is also displayed for navigation. Only problem is when i click the links to go to different pages the whole page reloads and still only reloads to show page 1. I cannot navigate to other pages. Me and damato were looking at a seperate pagination script and me and poco were looking at another. Both display everything fine but in both the links do not seem to work. They just reload page 1 of results again. Below is the code: <?php $username=$_SESSION['username']; $limit = 10; $query_count = "SELECT count(*) FROM goldies WHERE Sender='$username'"; $result_count = mysql_query($query_count) or die("Error: " . mysql_error()); $totalrows = mysql_result ($result_count, 0, 0); $numofpages = ceil($totalrows/$limit); $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:abs($_GET['page']); $limitvalue = ($page-1) * $limit; $query = "SELECT * FROM goldies WHERE Sender='$username' LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); //Exit if no records to display if(mysql_num_rows($result) == 0){ exit("Nothing to Display!"); } //Create the table of output data echo "<table>\n"; while($row = mysql_fetch_array($result)){ //Alternate the row background color $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373'; //Display the row of data echo "<tr bgcolor=\"$bgcolor\">\n"; echo " <td>".$row["Receiver"]."</td>\n"; echo " <td>".$row["Amount"]."</td>\n"; echo " <td>".$row["Date"]."</td>\n"; echo "</tr>"; } echo "</table>\n"; //Enable the Prev link if not first page if($page > 1){ echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); }else{ echo("PREV "); } //Create links for each page in report for($i=1; $i<=$numofpages; $i++){ if($i == $page){ echo "$i "; }else{ echo "<a href=\"creditshistory.php?page=$i\">$i</a> "; } } //Enable the Next link if not last page if($page < $numofpages){ echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); }else{ echo("NEXT"); } mysql_free_result($result); ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 6, 2007 Share Posted December 6, 2007 <?php $username=$_SESSION['username']; $limit = 10; $query_count = "SELECT count(*) FROM goldies WHERE Sender='$username'"; $result_count = mysql_query($query_count) or die("Error: " . mysql_error()); $totalrows = mysql_result ($result_count, 0, 0); $numofpages = ceil($totalrows/$limit); $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:abs($_GET['page']); $limitvalue = ($page-1) * $limit; $limitrange = $limitvalue+$limit; $query = "SELECT * FROM goldies WHERE Sender='$username' LIMIT $limitvalue, $limitrange "; $result = mysql_query($query) or die("Error: " . mysql_error()); //Exit if no records to display if(mysql_num_rows($result) == 0){ exit("Nothing to Display!"); } //Create the table of output data echo "<table>\n"; while($row = mysql_fetch_array($result)){ //Alternate the row background color $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373'; //Display the row of data echo "<tr bgcolor=\"$bgcolor\">\n"; echo " <td>".$row["Receiver"]."</td>\n"; echo " <td>".$row["Amount"]."</td>\n"; echo " <td>".$row["Date"]."</td>\n"; echo "</tr>"; } echo "</table>\n"; //Enable the Prev link if not first page if($page > 1){ echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); }else{ echo("PREV "); } //Create links for each page in report for($i=1; $i<=$numofpages; $i++){ if($i == $page){ echo "$i "; }else{ echo "<a href=\"creditshistory.php?page=$i\">$i</a> "; } } //Enable the Next link if not last page if($page < $numofpages){ echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); }else{ echo("NEXT"); } mysql_free_result($result); ?> [code] ok try .. [/code] Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 nope still the same problem i am using XAMPP is that matters Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 6, 2007 Share Posted December 6, 2007 nope.. try this put type the page in your url address and see if the page loads the right data eg.. if your page looks like this page =1 then type manually in url page=2 to see where to start looking Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 i did that and it again loads up page 1 Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 6, 2007 Share Posted December 6, 2007 i think im getting closer.. <?php $username=$_SESSION['username']; $limit = 10; $query_count = "SELECT count(*) FROM goldies WHERE Sender='$username'"; $result_count = mysql_query($query_count) or die("Error: " . mysql_error()); $totalrows = mysql_result ($result_count, 0, 0); $numofpages = ceil($totalrows/$limit); $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:abs($_GET['page']); $limitvalue = ($page-1) * $limit; $limitrange = $limitvalue+$limit; $query = "SELECT * FROM goldies WHERE Sender='$username' LIMIT $limitvalue, $limitrange "; echo $limitvalue.'<br>'; echo $limitrange.'<br>'; echo $query .'<br>'; $result = mysql_query($query) or die("Error: " . mysql_error()); //Exit if no records to display if(mysql_num_rows($result) == 0){ exit("Nothing to Display!"); } //Create the table of output data echo "<table>\n"; while($row = mysql_fetch_array($result)){ //Alternate the row background color $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373'; //Display the row of data echo "<tr bgcolor=\"$bgcolor\">\n"; echo " <td>".$row["Receiver"]."</td>\n"; echo " <td>".$row["Amount"]."</td>\n"; echo " <td>".$row["Date"]."</td>\n"; echo "</tr>"; } echo "</table>\n"; //Enable the Prev link if not first page if($page > 1){ echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); }else{ echo("PREV "); } //Create links for each page in report for($i=1; $i<=$numofpages; $i++){ if($i == $page){ echo "$i "; }else{ echo "<a href=\"creditshistory.php?page=$i\">$i</a> "; } } //Enable the Next link if not last page if($page < $numofpages){ echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); }else{ echo("NEXT"); } mysql_free_result($result); ?> try that and give the result if the echo i made from first page and upon next navigation Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 the links don't work and the following is echoed above table: 0 10 SELECT * FROM goldies WHERE Sender='WeedHunteR' LIMIT 0, 10 Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 6, 2007 Share Posted December 6, 2007 and what is the result when you click one of the page displayed? Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 when i click the link or put page 2 url in the address bar it still only reloads page 1 Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 6, 2007 Share Posted December 6, 2007 it might be something else not the code.. when you say you click page 2 does your url apears this way page = 2 so on .. or it remains as page = 1 hmm this is lot of post for paging lol Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 urgh i am so tired of this, i know, its a lot of headache just for numbering some pages and yes i do see page=2 let me post the whole code including html, maybe its something wrong there: <? include "includes/functions.php"; include "includes/db_connect.php"; session_start(); logincheck(); $username=$_SESSION['username']; echo "<link rel=stylesheet href=includes/in.css type=text/css>"; ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .style19 { font-size: 11px; font-weight: bold; } .style20 { font-size: 10px; font-weight: bold; color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; } --> </style> </head> <body> <table width="80%" border="0" align="center" cellspacing="5"> <tr> <td colspan="4"><div align="center" class="style19">History </div><br> <table width="100%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#000000" rules= class=thinline> </table></td> </tr> <tr> <td width="294" height=""> <?php $username=$_SESSION['username']; $limit = 10; $query_count = "SELECT count(*) FROM goldies WHERE Sender='$username'"; $result_count = mysql_query($query_count) or die("Error: " . mysql_error()); $totalrows = mysql_result ($result_count, 0, 0); $numofpages = ceil($totalrows/$limit); $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:abs($_GET['page']); $limitvalue = ($page-1) * $limit; $limitrange = $limitvalue+$limit; $query = "SELECT * FROM goldies WHERE Sender='$username' LIMIT $limitvalue, $limitrange "; echo $limitvalue.'<br>'; echo $limitrange.'<br>'; echo $query .'<br>'; $result = mysql_query($query) or die("Error: " . mysql_error()); //Exit if no records to display if(mysql_num_rows($result) == 0){ exit("Nothing to Display!"); } //Create the table of output data echo "<table>\n"; while($row = mysql_fetch_array($result)){ //Alternate the row background color $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373'; //Display the row of data echo "<tr bgcolor=\"$bgcolor\">\n"; echo " <td>".$row["Receiver"]."</td>\n"; echo " <td>".$row["Amount"]."</td>\n"; echo " <td>".$row["Date"]."</td>\n"; echo "</tr>"; } echo "</table>\n"; //Enable the Prev link if not first page if($page > 1){ echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); }else{ echo("PREV "); } //Create links for each page in report for($i=1; $i<=$numofpages; $i++){ if($i == $page){ echo "$i "; }else{ echo "<a href=\"creditshistory.php?page=$i\">$i</a> "; } } //Enable the Next link if not last page if($page < $numofpages){ echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); }else{ echo("NEXT"); } mysql_free_result($result); ?> </td> <td width="17"> </td> <td width="273"> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 6, 2007 Share Posted December 6, 2007 i think i get the error lol hold on buddy need to drink lol Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 6, 2007 Share Posted December 6, 2007 I had this same problem, and true enough it was my $page variable that was acting weird. I change it to $_GET['page'] and funny enough it worked just fine. Try it. or change //Enable the Next link if not last page if($page < $numofpages){ echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); }else{ echo("NEXT"); } to //Enable the Next link if not last page echo "page number : ". $page "<br>"; echo "number of pages : ". $numofpages; if($page < $numofpages){ echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); }else{ echo("NEXT"); } see what the numbers are Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\game\creditshistory.php on line 101 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 6, 2007 Share Posted December 6, 2007 how that? I added some more to my post, refer to it and tell me the results. Quote Link to comment Share on other sites More sharing options...
RealDrift Posted December 6, 2007 Author Share Posted December 6, 2007 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\game\creditshistory.php on line 101 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.