cooldude832 Posted October 11, 2007 Share Posted October 11, 2007 Is there a fasterway that doing a foreach($_GET) to get the 1,2,3,4 on a pagination?? Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/ Share on other sites More sharing options...
pocobueno1388 Posted October 11, 2007 Share Posted October 11, 2007 I don't follow...explain more. Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366694 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 Is there a fasterway that doing a foreach($_GET) to get the 1,2,3,4 on a pagination?? what ??? Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366695 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 I did this <?php $url = $_SERVER['PHP_SELF']."?"; $and_set = 1; foreach($_GET as $key => $value){ if($key == "limit"){} if($and_set != 1){ $url .= $key."=".$value; $and_set = 1; } else{ $url .= "&".$key."=".$value; } } ?> to get a formatted url for my pagination, however I can't help to think it could be simpler. Then again any simpler method would return the full query string and you couldn't mod the limit variable as easily. Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366696 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 can you show your sample of your url ? im confuzed with the way your doing it i havent seen any paging using foreach for GET[] Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366699 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 I'm trying to reproduce a url for the next, prev 1, 2, 3 ,4 ,5 links you put on a pagination page so you can get to the rest of the results, I use the foreach to get all the get variables and I restricted the limit so that I can modify it manully Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366700 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 to have prev 1 2 3 4 5 you simply divide numrows from limit number of records to be displayed so i suppose it should for loop not foreach to get get variables i mean all you can use query string $_SERVER['QUERY_STRING'] hmm ? Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366703 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 I'll show you the whole thing, tell me if u see an improvment <?php $url = $_SERVER['PHP_SELF']."?"; $and_set = 0; foreach($_GET as $key => $value){ if($key == "limit"){} if($and_set != 1){ $url .= $key."=".$value; $and_set = 1; } else{ $url .= "&".$key."=".$value; } } //This is the output it can be anywhere below the above (I like it above and below the search results) if($page >1){ $temp = $page-1; echo "<a href=\"".$url."&limit=".$temp."\">Prev</a>"; } for($i = 1; $i<=$num_pages; $i++){ if($i == $page){ echo "<span class=\"current_page\">"; } echo " "; echo "<a href=\"".$url."&limit=".$i."\">-".$i."-</a>"; echo " "; if($i == $page){ echo "</span>"; } } if($page < $num_pages){ $temp = $page+1; echo "<a href=\"".$url."&limit=".$temp."\">Next</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366706 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 firts why do you need to ad that limit in your query string! Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366708 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 because it outputs the whole html part <a href="/redesign/search.php?search=yes&type=2&location=all&month=Any&year=2002&limit=2&limit=1">Prev</a> <a href="/redesign/search.php?search=yes&type=2&location=all&month=Any&year=2002&limit=2&limit=1">-1-</a> <span class="current_page"> <a href="/redesign/search.php?search=yes&type=2&location=all&month=Any&year=2002&limit=2&limit=2">-2-</a> </span> <a href="/redesign/search.php?search=yes&type=2&location=all&month=Any&year=2002&limit=2&limit=3">-3-</a> <a href="/redesign/search.php?search=yes&type=2&location=all&month=Any&year=2002&limit=2&limit=4">-4-</a> <a href="/redesign/search.php?search=yes&type=2&location=all&month=Any&year=2002&limit=2&limit=3">Next</a> If I don't sort the limit out of it, then can't adjust its value in the ouptutted string "easily" this method lets me edit it very easily in the url, as its not part of it to start. Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366710 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 the easiest way i see is class i guess it would be better if you will use classes so can just have it like this $paging->limit = 20; $pages = $paging->rows(select statement); and everything is done within 2 lines Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366725 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 I'm not a class kinda person (not that i'm not classy ), but I just dont' see a better solution for what I need. I could rewrite the url based on what I did the query with, but that seems like more work. Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366727 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 dude you really have to learn it now i unders tand what your trying to obtain with that limit you want to use function that is dynamic tru the help of get limit right? and this foreach($_GET as $key => $value){ if($key == "limit"){} if($and_set != 1){ $url .= $key."=".$value; $and_set = 1; } else{ $url .= "&".$key."=".$value; } } why need to loop since you use $key == "limit" why not access them directly nad get value and key http://www.php.net/manual/en/function.array-keys.php Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366735 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 I thought about that, however I need to extract that one thing off, I could pop off the limit and then implode it as u say Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366738 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 or maybe you can have your paging in a function and add a parameter that will hold your limit value as well as the link location for($i = 1; $i<=$num_pages; $i++){ where do you get $num_pages actually paging is simple so no hard work needed Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366745 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 $num_pages is equal to $count (from mysql) divided by $per_page Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366747 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 function paging($query,$pagelimit,){ $_mysql = mysql_query($query); $rows = mysql_num_rows($_mysql) / $pagelimit; $limit = $_GET['page']*$pagelimit; $mysql_display = mysql_query($query.'limit '.$limit-$pagelimit.','.$limit); while(mysql_fetch_assoc($mysql_display)){ //display record on that field } //limit pages to be displayed in 5 if ($rows >1){ $ivalue = ($_GET['page'] >5 )?$_GET['page']-4:1;// determine where to start for($i = $ivalue; $i <=$rows; $i++){ ++$ctr; if ($ctr >=5){ //display here your link for paging $href = echo "<a href=\"".$_SERVER['PHP_SELF']."?page = $i\">-".$i."-</a>"; } } } } note not tested no returns i just want to show you how im going to do it without a class or do it on my way i know you can edit this if this make sense dude post here your updated code if you will use my idea Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366760 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 right now its not affecting speed, and that breaks the flow I have set as I query above where I output. So until it becomes a speed issues I'll stick with what i got Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366763 Share on other sites More sharing options...
teng84 Posted October 11, 2007 Share Posted October 11, 2007 yah Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366764 Share on other sites More sharing options...
cooldude832 Posted October 11, 2007 Author Share Posted October 11, 2007 I'm actually a bit surprised on its speed as its a 11kb doc 364 lines and it loads in less than a seconds, but I haven't added any images to the output yet. But I'm not disappointed at all with it:) Quote Link to comment https://forums.phpfreaks.com/topic/72710-getting-a-url-for-pagination/#findComment-366768 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.