er0x Posted September 12, 2007 Share Posted September 12, 2007 i have the script set up to show 10 results per page... shows the 10 fine... just doesnt show the links to go to the other pages of links. so i can only see the first 10. LINK TO SCRIPT -http://er0x.byethost6.com/?page=links i would like it to work with the ?page=links url... like ?page=links&page=1 or something like that... so heres my code. please help... <font size="2" color="008aff"><a href="?page=links/submit">Add a link</a><br /><br /> <?php $host = "sql1.byethost6.com"; $username = "xxxxxxxx"; $password = "xxxxxxxx"; $db = "xxxxxxxx"; mysql_connect($host,$username,$password) or die ("error"); mysql_select_db($db) or die("error"); $limit = 10; $query_count = "SELECT count(*) FROM links"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM links LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } $color = array("#353535","#3a3a3a"); $tcolor = #008aff $num_colors = count($color)-1; $i = 0; echo "<table>"; while($row = mysql_fetch_array($result)){ //Resets the color counter to 0 if it gets too high if($i > $num_colors){$i = 0;} echo "<tr bgcolor=\"".$color[$i]."\">"; echo " <td width=\"375\"><a href=\"".$row['link']."\" target=\"_blank\">".$row["linkname"]."</a> <font color=\"008AFF\"> - ".$row["description"]."</td></tr>"; $i++; } echo "</table>"; if($page != 1){ $pageprev = $page--; echo"<a href=\"?page=links&page=$pageprev\">PREV".$limit."</a> "; }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo"<a href=\"?page=links&page=$i\">$i</a> "; } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo"<a href=\"?page=links&page=$i\">$i</a> "; } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo"<a href=\"?page=links&page=$pagenext\">NEXT".$limit."</a>"; }else{ echo("NEXT".$limit); } mysql_free_result($result); ?></font> Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/ Share on other sites More sharing options...
cooldude832 Posted September 12, 2007 Share Posted September 12, 2007 I see its a pagination this time you have a live link to it, otherwise give me a sec to look through it see live link 1 sec Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/#findComment-346515 Share on other sites More sharing options...
cooldude832 Posted September 12, 2007 Share Posted September 12, 2007 alright I see a very early problem <?php if(empty($page)){ $page = 1; } ?> In this bit I'm assuming you are trying to get the page number from the url so you need to include $page = $_GET['page'] and also you should run it like this <?php $page = $_GET['page']; if(empty($page) || !is_numeric($page)){ $page = 1; } ?> That being said you need your url to be structured like http://er0x.byethost6.com/?page=links&page=1 as you said. now lets look at the rest. You are querying for the total number of pages already just don't use that * operator, instead use the primary key of the table since it will save you a lot of resources. The error i'm seeing is in your echoing of the links try this instead of your current link echoing <?php echo"<a href=\"".$_SERVER['self']."?page=links&page=$pagenext\">NEXT".$limit."</a>"; ?> Otherwise I'm going to say that you need to make sure your outputted values for the number of results/rows/pages make sense, by simply echoing them out after they are established to verify their values. Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/#findComment-346518 Share on other sites More sharing options...
er0x Posted September 12, 2007 Author Share Posted September 12, 2007 ok well, i have changed the code to with what u said.. they still arent showing up as links. but i was playing around with it and discovered that echo"<a href=\"".$_SERVER['self']."?page=links&page=$pagenext\">NEXT</a>"; }else{ echo"<a href=\"".$_SERVER['self']."&page=$pagenext\">NEXT".$limit."</a>"; will display it as a link but the page it links to doesnt work... goes to http://www.er0x.byethost6.com/?page=links&page= but no page number. regular code is... echo"<a href=\"?page=links&page=$pagenext\">NEXT".$limit."[/url]"; }else{ echo("NEXT".$limit); // this is the line it is displaying (linkless) Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/#findComment-346611 Share on other sites More sharing options...
er0x Posted September 12, 2007 Author Share Posted September 12, 2007 still nothing? Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/#findComment-347140 Share on other sites More sharing options...
cooldude832 Posted September 12, 2007 Share Posted September 12, 2007 <?php echo"<a href=\"".$_SERVER['self']."?page=links&page=$pagenext\">NEXT</a>"; }else{ echo"<a href=\"".$_SERVER['self']."&page=$pagenext\">NEXT".$limit."</a>"; ?> try this instead <?php echo"<a href=\"".$_SERVER['self']."?page=links&page=".$pagenext."\">NEXT</a>"; }else{ echo"<a href=\"".$_SERVER['self']."?page=."$pagenext."\">NEXT".$limit."</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/#findComment-347152 Share on other sites More sharing options...
er0x Posted September 12, 2007 Author Share Posted September 12, 2007 well, it fixed the link part. but its still not pulling the next pages, page number so it shows as ?page=links&page= Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/#findComment-347307 Share on other sites More sharing options...
cooldude832 Posted September 12, 2007 Share Posted September 12, 2007 i'm seeing the next/previous ten doign so, but I don't see it in your script Quote Link to comment https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/#findComment-347407 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.