[how?] PHP search

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Nerfintas
Posts: 54
Joined: Wed Aug 28, 2013 6:01 pm

[how?] PHP search

Post by Nerfintas »

Hi guys. Need some help, i want to do my search. For example i have a tab with a bit list in my list1.php list2.php and list3.php and i need to make a search.php where i can find line from tab with keyword. For example:
list1
Indie Resource
Indie Games
Batman Returns
list2
Indie Team
Spiderman Returns

in Search: Indie
Result:
Indie Resource
Indie Games
Indie Team

EDIT: and is there a way without database, without cms and etc a function or script or smth to add a line in a list without editing list1.php? like add.php
EDIT2: and is there a way to include filter to show my tab by abc?:D
Last edited by Nerfintas on Wed Sep 25, 2013 5:06 am, edited 1 time in total.
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: PHP search

Post by vitinho444 »

Ok, for the search thing i made this a while ago for my college review website.

Code: Select all

if(isset($_POST["keyword"]))
                    {
                        $needle = $_POST["keyword"];                        
                        
                        $searchT = Query("SELECT * FROM `TABLE` WHERE `FIELD` LIKE ?", "%".$needle."%");                        
                    }
                    else
                    {
                        echo "
                        <form method='POST' action='search.php'>
                        <p>Search for:<input type='text' name='keyword' class='search'> <input type='submit' class='searchButton'></p>
                        </form>
                        ";
                    }
 
So what you need to take from my code, is to change the TABLE to the name of the table you want to search, and the FIELD to the name of the field.

With this code if you input Indie and search on List1 you would get every row that contains the title Indie
Example:
Indie zone
Indie resource
resource Indie
Ugly Indie
DumIndiemy
AFJIFJAIndieDFSAUFNAF

etc

Hope it helps.

About the first edit:
I think you mean how to insert values into a table using php?

Just do a query

Code: Select all

"INSERT INTO `TABEL` ('field1', 'field2') VALUES ('vitor', 'indie')"
What this will do is Insert the values "vitor" and "indie" into field1 and field2.

I think that's what you want :)

About your EDIT2:
It's easy, whenever you do a query
Let's say this is the query:

Code: Select all

SELECT * FROM `TABLE`
and you want to display the results sorted by some field, lets say by date
so you do:

Code: Select all

SELECT * FROM `TABLE` ORDER BY `date` DESC
What this does, is getting all rows from TABLE and order them by date.
Note: date field must be an actual field from the table "TABLE".


Just realized that i've helped a lot.. so this is how jacko and the guys that help a lot feel.. damn its good.
Last edited by vitinho444 on Wed Sep 18, 2013 7:32 pm, edited 1 time in total.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Nerfintas
Posts: 54
Joined: Wed Aug 28, 2013 6:01 pm

Re: PHP search

Post by Nerfintas »

thanks! a lot of information :)
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: PHP search

Post by Epiales »

vitinho444 wrote: Just realized that i've helped a lot.. so this is how jacko and the guys that help a lot feel.. damn its good.
You're always helping! YAY you :) Thanks for all ya do :mrgreen: ;) ;)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: PHP search

Post by vitinho444 »

OH STOP YOU GUYS :oops: :oops: :oops: :oops: LOVE THIS COMMUNITY
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Nerfintas
Posts: 54
Joined: Wed Aug 28, 2013 6:01 pm

Re: PHP search

Post by Nerfintas »

this community loves u :DD
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: PHP search

Post by vitinho444 »

you guys are making me shy :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Nerfintas
Posts: 54
Joined: Wed Aug 28, 2013 6:01 pm

Re: PHP search

Post by Nerfintas »

i was tried but im green in it.. can u make me a working example? for search.php and for list1.php ?;/
Post Reply

Return to “Beginner Help and Support”