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
Related
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
This question may have been asked before but I couldn;t really find it.
What I want to do is, websites like pastebin.com, even stackoverflow, these generate new webpages based on user input showing that data from what I can understand.
I want to make it like that. User enters something, and he is given a permalink to share that information.
How to do this using PHP ?
EDIT: Here is an example
Like, I want it that
instead of having something like www.example.com/view.php?id=123
I want it like
www.example.com/view/123
This is impossible to be done with PHP, you can do this with .htaccess's url rewriting.
a good article about this can be found at: https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
In this site , work some ajax function, when you add some data in textarea and click submit, called function , that saved current data in db, and return some json data , and then show you in some format.
Simply done like this:
Create a index.php containing a input field where the user inputs their data.
Post data to the server and create a random string which will be the users permalink.
Then insert the random string and data into a database.
In the index.php file say that if any uri is added after your domain like example.com/
it checks against the database if this code exists in db, and returns the result to the visitor.
I've built a webpage that, in its products page has this prototype for its url
http://www.example.com/products/show/some-really-nice-product/512
The last bit of the url is the product id, which serves the sole purpose of searching the db for the product.
But, is it possible, using routing, to be able to hide that part and still be possible to search the product by its id?
Like
http://www.example.com/products/show/some-really-nice-product/ ??
Thank you
If you don't want to put a number in your URL, you can't later search by a number/id :)
So you could add a VARCHAR field to the table, say "urlized", and use "some-really-nice-product" as its content for the given ID (you'll need to 'urlize' all your product names and make them unique). Don't forget to index your new field...
Then, you could access the product page using this URL which is very SEO friendly (ends with ".html"):
http://www.example.com/products/show/some-really-nice-product.html
...by adding a route to CodeIgniter, somehow like this:
$route['^products/show/(.*).html'] = 'products/show/$1';
In your controller/model, search the database for the string that is passed to "show" method, instead of the ID
if you hide id you can't retrieve that from the url anymore
if you want to hide that anyway just do:
$route['products/show/(:any)'] = "products/show/$1/$2";
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.
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