Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

multiple search pages

Recommended Posts

Now it's time for me to figure out how to set up a search area, that adds pages for items over 20.  I am wanting to drop a list of about 100 links on a page, leading to various post's then when it get's to 100 I am wanting to cut it off, and start showing page 1, and page 2, excetera , if there were like 600 posts, then there would be 6 pages, and so forth, any advice??  Or a place to start, I know everything I need to know about db calls, it's just figuring out how to get the other page to dynamically create based on the number of posts?

Share this post


Link to post
Share on other sites
heres my script that i use for a marketplace....it has paginating on it... EDIT: I have cut out alot of code to help narrow down the paginating

[code]<?PHP
if(isset($_GET['s'])){
$start=$_GET['s'];
}else{
$start=0;
}
$display = 10;
$counting = "SELECT COUNT(*) FROM listings ORDER BY id ASC";
$showing = "SELECT * FROM listings LIMIT $start, $display";


$page = "$counting";
$resultp = mysql_query($page);
$row = mysql_fetch_array($resultp, MYSQL_NUM);
$num_records = $row[0];

echo "<p align=center>There are $num_records Listings</p>";
if(isset($_GET['np'])){
$num_pages = $_GET['np'];
}else{
$page = "$counting";
$resultp = mysql_query($page);
$row = mysql_fetch_array($resultp, MYSQL_NUM);
$num_records = $row[0];
if($num_records > $display){
$num_pages = ceil($num_records/$display);
}else{
$num_pages = 1;
}
}
$query2="$showing";




if($num_records > $display){
$num_pages = ceil($num_records/$display);
}else{
$num_pages = 1;
}


if ($num_pages > 1){
echo '<br><p>';
$current_page = ($start/$display) + 1;
if($current_page != 1){
echo '<a href="browse.php?s'.($start - $display).'$np='.$num_pages.'">Previous</a> ';
}
for($i =1; $i <= $num_pages; $i++){
if ($i != $current_page){
echo '<a href="browse.php?s=' . (($display*($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> ';
}else{
echo $i.'';
}
}
if($current_page != $num_pages){
echo '<a href="browse.php?s='.($start + $display).'&np='.$num_pages . '">Next</a> ';
}
}
?>
</html>[/code]

Share this post


Link to post
Share on other sites
Ok here is the thing, I am developing something, I sort of understand the general theory.
I create my queries, limit it, at like 60 since there just links
so I would use limit 60
I know then on the other page, THe next query would be
LIMIT 60, 60
then
LIMIT 60, 120
that would telll it limit 60 starting at row 120, then on the next it's like
LIMIT 60, 180
and so forth, I know about this part, I also know how to get the links to appear, or I can come up with something, what I don't understand is do I have to create a physical page for each occurence.  Like do I have to create test
test1, test2, test3, test4, test5 and so forht, even if there not all used all the time
so it would show 60 on test 1, 60 on test 2 and so forth.
But that makes me also wonder because I have to do this same thing, in about 100 different areas, I have to make it paginate seperately for each category, sub-category, and when they run specific search criteria?

Share this post


Link to post
Share on other sites
See this is my fear.  I have to get  a search set up, and there are a lot of categories and sub-categories, I will probably some how find all of them to run through one page, I normally come up with something, but I have to get them all working with paginate< i am brainstorming idea's right now, but in case I can't come up with something there is no way I could have 10 physical .php locations for each occurence, to check for all possible numbers.  I have to find a way to autogenerate the queries, on the other pages, without creating physical manifestations of those pages, for each set of queries. Like 10 pages for each category, 10 for each subcategory, that will range around 250 pages total by the time I am done, with like 20-175 that aren't in use most of the time.  THen if the queries get larger than that, then I don't have enough pages to cover it.

Share this post


Link to post
Share on other sites
also I just got an idea.
I can put the page back onto itself.
For instance I can have a query
and inside the query I can limit it to 10, and capture the result, using count, or num_rows, to get the number of row's I have.  THen when the links are clicked, it sends it back on itself, containing a variable in the url, that populates the query.  Then the query just get's repopulate on itself, and upgrades it's number's over and over again.

Share this post


Link to post
Share on other sites
Actually I have an idea for the framework at least.
I will take and pull the url, I will cut it up, and pull out the individual information to retrieve the category, and subcategory it's coming from, then I can populate my search using that category and subcategory.  That will take care of that issue.  Then for my pagination, I can contain another variable, that is going to record the number of rows, then based on the number, i can display the appropriate number of links.  Then those links, feed it back onto itself, and they should repopulate the mysql query again with teh proper numbers to display, the onyl thing is, I have to find a way to keep it from repopulating some random for category and subcategory.  I just have to prevent it, because hte url won't contain the category or subcategory anymore so it might end up running an emtpy query and breaking the whole thing, I have to consider that too.

Share this post


Link to post
Share on other sites
I might be able to temporarily store them in sessions, with just like a 15 second lifespan.  Then that will keep the category and subcategory saved just long enough for me to be able to repopulate my fields.  I might be able to get it to run smoother like that. 

Share this post


Link to post
Share on other sites
I am setting up the frame work to split the directory information to retrieve the category and subcategory now, once I get it working, I am going to make sure the variables are passing, then redo all my links to point to that same page, for all the found items.  Then after I have them all running towards it, I will write a general query and populate it with category and subcategory based on the link directory.
After that I am going to try and see about saving the number of rows, and using if statements, or a case switch probably to test the number of total result's so I can produce the appropriate number of links.
Then I can try to dynamically set the numbers to work with when it repopulates the query, then all I ahve to figure out is how to carry over category and sub-category, with some modifications I can probably dynamically populate it through each url, to come back on itself, but then it might conflict with me splitting the directory.
hmm

Share this post


Link to post
Share on other sites
Thanks.
I just figured out one thing.
I am going to ahve one page to recieve the information coming from category and sub-category to populate my query, like view 1.  Then all of those links, ALL of them are going to point to view 2, the links that show more.  The will go to view 2.  I will pass the category and subcategory via get to the other page, as well as the number of row's that I left off on, and the limit number, which is whatever I choose to limit it at.  THen for each link, I can easily pass through all the variables.  I can make the links go up to like 10 pages, that will make sure that it atleast lasts for awhile, if I have number problems I can probably, go back and just add a few more pages as needed. 10 pages should last for the lifetime of the site atleast.  That would be a lot of posts per category, especially if I make 100 the limit, it should keep things running smoothly for quite a long time, but then I also have to sort based on the entry date, actually I made a miscalculation during entry, I have to record the date's they were entered to, just not a date that keeps getting updated.

Share this post


Link to post
Share on other sites
well I could sort by id number too.  Because the newest numbers would have course been entered first, I have to do something about the entry date anyway, it has to show the date they were entered so people atleast know when it was entered.  I have to work that out first.

Share this post


Link to post
Share on other sites
Ok I just fixed all the issue's relating to the date, now it records the date, and shows the date, and email's the date, I redid all of that, now I can concentrate on making this work.
I am going to go ahead and work up all my categories and sub-categories, and hte page to recieve those requests.  Then I am going to set up the directory splitter, and cut it up to recieve the category and sub-category.  Then display 100 results, and start recording the information I need and display the pages.
I have accounted for everything except one thing I forgot, I have to get the number of pages as well to produce on the other page, so they can be viewed.

Share this post


Link to post
Share on other sites
ok now I could use some help, I know how to set up redirects and they normally work well.  The thing with this is it's acting up, when it activates the redirect in order to get out of it you have to click on a link 2 times
like
this is my htaccess
[code]Redirect /found http://www.elostandfound.info/viewfound.php[/code]
Now the folders are like that, when they choose a category, then the sub-category it redirects to
http://www.elostandfound.info/viewfound.php/category/subcategory
just like that in the url, taking me to the page I need, and giving me the info from the links I needed to get the process to start.  But when you try to click on another page, for instance the homepage, or the account page.  It does something wierd, like if I click the account page the first time it becomes
http://www.elostandfound.info/viewfound.php/myaccount.php
and if I click the homepage first instead it's
http://www.elostandfound.info/viewfound.php/index.php
it starts to chain it, the first link you click on changes the url to match the name of the page, then whatever else you click on after that takes you out of the page, why is this happening?

Share this post


Link to post
Share on other sites
i see that you have the links like this
[code]<a href="../index.php">Home</a>[/code]
Well the browser actually thinks that http://www.elostandfound.info/viewfound.php/category/ is a directory and tries to go to http://www.elostandfound.info/viewfound.php/index.php.

if you do this instead:
[code]<a href="/index.php">Home</a>[/code]
then the browser knows that you're accessing the index.php of the top level.

Share this post


Link to post
Share on other sites
that works but when going deep on some pages, the only way access seems to work is if I use ../
but I will try that now and see if it works.

Share this post


Link to post
Share on other sites
wait, I was ALWAYS taught, that if you are on the root folder you can access everything on the same, even if your in a sub-folder you can use just
whatever.php
but if you were in a sub-directory calling a page in the root directory it was
./whatever.php
and then 2 levels deep was
../whatever.php
are you tell me all I have to do is put
/whatever.php
and I can access the link from any page???

Share this post


Link to post
Share on other sites
because I always have trouble getting access to my css pages, when I am a couple of levels deep in a directory I thought I always had to put ../

Share this post


Link to post
Share on other sites
/ is the root. even if you're in the shell, you can access the root files by using /root.pl. therefore, you always see this kind of thing in a perl script like /usr/bin/perl

whatever.php or ./whatever.php is the current directory
../whatever.php is one up
/whatever.php always give you the root

Share this post


Link to post
Share on other sites
[code]../whatever.php is one up[/code]
ok let me recap one more time, tell me if I am right, I just need to get this memorized now.

Ok root directory can always be accessed
with
/whatever.php
that pulls the root directory, if I am in a sub-directory or lower, I can still use
/whatever.php to pull a root directory file out.
Ok now if I am in a folder, in one level, I use
for getting to a file within that SAME directory I can use
whatever.php
what does
./whatever.php do, with just one dot. 
and ../whatever.php do with 2 dots what are the 2 different between those
I understand
/whatever.php is root directory
whatever.php is for whatever directory I am in, if the file I am accessing is in the same directory this will access it
what is ./ and ../
the reason I am confused is I have includes
in /include/whatever.inc.php
and I always when I enter my includes it is always
include './includes/whatever.php'
or if I have a nav in an include, on every link in my nav if I put ../ before each one anyway I don't normally have problems.  How do I know the difference??  Sorry to ask this, but you have taught me something I had no idea about and it'll make my job 100 times easier in the future.

Share this post


Link to post
Share on other sites
../ means go one level up. if you're in /root/level2/level3, ../ gives you anything in level2. you can use ../../ to get to root from level3 too.

the one dot basically mean the current directory. i don't use it often, but i guess it might be useful on some cases. someone correct me on this if i'm wrong.

i'm not saying that you should always use / and abandon ../. just choose whichever is best for you in a situation.

Share this post


Link to post
Share on other sites
well bottom line is what you told me fixed the problem in this situation, and even if I continue the other method this is something I will definitely keep in mind for other situations where I encounter similar options.  Thanks ryan.
Also if your reading this wildteen, in a post you put down yesterday a theory that helped me tremendously
<?php
echo "Debug Information";
echo "<br />"
echo "Contents of variable whaever



echo "End Debug Information";
?>
whatever like that, when I encounter massive problem I take 5 minutes to create an entire debug program to just empty all my variables, check all my calculations and everything where I am having the problem and within 4 minutes I calculated the location of the problem and fixed it.

Share this post


Link to post
Share on other sites
umm wow i got lost there..but i think one of the things you said was searching through catagorys and displaying...i dunno but if so in the original code i had searching through catagorys working with paginating...i can show if you want...

Share this post


Link to post
Share on other sites

×

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.