Page 1 of 1

[how?] PHP search

Posted: Sat Sep 14, 2013 6:55 am
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

Re: PHP search

Posted: Sun Sep 15, 2013 6:35 pm
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.

Re: PHP search

Posted: Sun Sep 15, 2013 7:33 pm
by Nerfintas
thanks! a lot of information :)

Re: PHP search

Posted: Sun Sep 15, 2013 7:35 pm
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: ;) ;)

Re: PHP search

Posted: Sun Sep 15, 2013 9:12 pm
by vitinho444
OH STOP YOU GUYS :oops: :oops: :oops: :oops: LOVE THIS COMMUNITY

Re: PHP search

Posted: Mon Sep 16, 2013 4:51 am
by Nerfintas
this community loves u :DD

Re: PHP search

Posted: Mon Sep 16, 2013 8:39 am
by vitinho444
you guys are making me shy :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:

Re: PHP search

Posted: Wed Sep 18, 2013 5:46 pm
by Nerfintas
i was tried but im green in it.. can u make me a working example? for search.php and for list1.php ?;/