Paginator doens't store search parameters - php

i'm using jpinedo.webcindario.com/scripts/paginator at my search script, but when i click on the page 2 the parameters from the first search are lost (i get my own message for "you need to type at least 2 characters")
how can i make it work?
this is my search.php:
$q = mysql_real_escape_string($_POST['q']);
$option = mysql_real_escape_string($_POST['option']);
that are coming from my index.php, search module
(the rest are just the same from the script example, a simple search)
i tried:
$_pagi_propagar = array("q","option","search");

You want to make your search GET based instead of POST based. This is because clicking a link is always GET based, so it's easier to change the search submit to GET than change the links to POST, since that requires a fair bit of javascript.

Related

Create a url shortcut for a ajax search field 3

I'm trying to create a shortcut to a page with a search value included. For example in this page :
https://adminlte.io/themes/v3/pages/tables/data.html
There is a search field in the middle of the screen which is live (ajax) and when you type
1.8 it limits results to 8.
Can i create a url to show directly this "filtered data page " ?
something like this ->
https://adminlte.io/themes/v3/pages/tables/data.html?Search="1.8"
If I understood your question correctly, you want to pass a parameter to the search field and the search field functionality is done with javascript. In this case, you can pass a parameter like in your example, but then it will have to be in the code of the search functionality that your read the parameter and act accordingly, for example by reading window.location.search https://developer.mozilla.org/en-US/docs/Web/API/Location/search

How to create a search system like Unsplash?

When I create a search bar I always use the GET method. If a person searches for the word "code" the link will be: www.mywebsite.com/search?q=code
But at Unsplash, when you search the word code the link will be:
https://unsplash.com/search/photos/code
I copied this link, and I wrote all the words, even my first name (https://unsplash.com/search/photos/zayad) and I found a page with the images related to the searched words.
Do you have an idea on how, can I do the same thing in my website?
JavaScript. They intercept the form submission, update the address bar and redraw the page using JavaScript.
On the results page, they parse the URI in the address bar, make an AJAX request based on the search term they extract, and then update the page with the returned results.
Unsplash uses angularjs, that allows you to pass text from your text box as parameters quite easily. Wappalyzer says that Unsplash uses angularjs. Check out angularjs

Change form submission from GET to POST PHP

I'm working on big site and it has filtering of cars in it. I'll explain how the form filtering works:
so the user chooses filter options, car number and so and presses go, which makes GET request to server (php) i've changed every variable from $_GET to $_POST and changed form submission method, the problem is that when form returns big number of items it might have more than 2 pages, so when the user clicks on second or third page all this code does is add page number to the request like this: www.example.com/GET_REQUEST_VARIABLES -> www.example.com/pagenumber&GET_REQUEST_VARIABLES. that way server returns second page items and so.
but when i send post request, it isn't saved in the url so server doesn't know what to return,
can you help me solve this problem?
i can explain better if you ask questions i don't know if i explained clearly here
Is there a reason you are using POST instead of GET? Using GET is more SEO friendly in this case. And since you aren't sending sensitive data in the form submission, I don't see a reason to use POST. Another advantage of using GET is that you can directly link to search results. (For instance, if I search for a Honda Fit, and want to show my wife, I have a direct link to the page)
(Look HERE for a bullet-point explination of the difference bewteen POST and GET).
To answer your other question, POST does not use the URL. Only GET does So if you need the form data to be serialized into the URL, you'll need to use GET. Since you changed the form submission method to POST, you'll need to change the server side logic as well to accommodate. I can't be of much use without knowing what server-side technology you are using. Assuming you are using PHP, you could start here
If you aren't much for MAN pages, just change all the $_GET['fieldName'] calls in PHP to $_POST['fieldName']
You could always POST the first page, and use GET ONLY for the page number. In the form you would just do this
<form method="post" action="www.foo.com/search?page=1">
Then you can store your POSTed variables into the $_SESSION super-global. BOOM. POSTed pagination. It would be a breeze to render it on the fly with PHP
$nextPageURL = 'www.foo.com/search?page=' . $_GET['page'] + 1;
if($_GET['page'] !== '0'){
$lastPageURL = 'www.foo.com/search?page=' . $_GET['page'] - 1;
}

Passing Variables between PHP pages then performing a MySQL search

fairly new to PHP and webdesign.... I have a website which has a bunch of products for vehicles - all of this is stored in a database.
In order to narrow down what products are available, I want to take the user through 2-3 pages where they firstly select what categorey of product they want, then what make of car they have, then the model, then I want to run a mysql query with that information and return the answerson a page.
I already have the code to request the info from a database and then display it on the page, but The way the current website is setup, they are hard coded mysql queries (meaning the user didnt input any data to get there).
So how can I transfer variable between php pages? Page 1 (contains Categorey) - then pass to Page 2 (contains Make) then page to Page 3 (contains Model) then compile the three variavles collections, and pass them to results.php (a standard results page which Gets variables and then searches).
I know this might seem basic, but I am really stumped as to how to get it coded.
If someone can give me an a newbie explanation about how to achieve this? Thank you
You can pass PHP variables through URLs for example
Your HTML code,
<a href='yourPage.php?yourVariable=someValue'>TEST!</a>
Your PHP code,
if (isset($_GET['yourVariable'])) {
$yourVariable = $_GET['yourVariable'];
// Your code here.
}
Now using this you can create what you want with a little bit of tinkering.
Remember
You need to use $_GET because parameters are being passed using the URL and not a POST request.
Don't forget to clean all input.

Is this way of doing this the 'better way'?

I have a advertisement website with alot of records stored in a mysql db.
On my main page, I have a form where users may specify their search criteria.
Action is set to myPhp.php file.
myPhp.php contains NO HTML, only php code, and it is basically something like this:
1- get values from FORM and build a SQL query
2- query MYSQL db.
3-display all results in a table using
`while($row=mysql_fetch_array($res))`
4- echo the table.
In this table which is created in PHP, I have several links also, and whenever they are clicked, a javascript function on the parent page is called, which sets a hidden input value to something, and then submits the form again with the chosen variable.
Ex: Whenever users want to go to the next page in the search results, they have to click on a 'next' link created in PHP, and then the javascript gets called, which sets a hidden input value to 'next', and then the form is submitted again, and PHP file GETS the variable from the hidden input and detects that its value is set to 'NEXT' and then displays the next results.
Is there really not another way to do all this ? (that is, a better way when it comes to performance and reliability)
Im still learning so I am very thankful for your help!
I will update this Question whenever you need more input.
Thanks
Replace the next javascript call with a link to
http://yourdomain/myPhp.php?page=2
Then check the get parameter in myPhp.php:
if(isset($_GET['page']) AND is_numeric($_GET['page'])){
$limit = (int) $_GET['page'] * MAX_RECORDS . ', ' . MAX_RECORDS;
} else {
$limit = MAX_RECORDS;
}
//...
$query .= 'LIMIT '. $limit;
Of course you have to change it as your constants change and such.
This method called paginating. Take a look at the Zend Framework's Paginator module to the better understanding.
When creating the link you can use a querystring to specify the parameter that you would like to send to the server rather than submitting a form. So if you have a hidden input in a form called next then you can accompish the same thing like this:
Next
On the myPhp.php page you can get the value of next in a similar way as when you send a form.
If these links have at least one same class across board (with a title attribute) you can attach to them to can attach all these links to a single click event and test to see what title is on the element clicked.
With that you can use a switch to trigger the right function to perform the task (I suppose using JQuery/Ajax).
This should work. At least no hidden fields.
Example:
Next
Ad Details

Categories