How do you create a search box to search a MySQL database?
I want to put alot of names of song artists in a database, make a search box on my website, and that Artist would appear. Then the person could click on the artists name, which would bring them to another site. Could someone pelase tell me how to do all of this? Thanks.
Comments
Well you are talking about two separate languages the first is SQL and the second could be PHP, ASP.NET, VB.NET or C#
The SQL part is easy it would simply be the following
If your database is like this
Table Artists
COLUMN TYPE NULL? OTHER
artistID int NOT NULL IDENTITY(1,1),
artist nvarchar(50) NOT NULL,
album nvarchar(50) NOT NULL,
AlbumDate smalldatetime NULL
Then you simply use this SQL statement
SELECT artistID, artist, album, albumDate FROM Artists WHERE artist=@artist
That is the basics in sql...
Now for the next part lets say you are doing vb.net it would be like this
Search.aspx with the searchbox called searchTextBox
Dim cn as new sqlconntection(connectionString) *you enter your own connection string
Dim cm as new sqlcommand
cn.open()
With cm
.commandtext = "SELECT artistID, artist, album, albumDate FROM Artists WHERE artist=@artist"
.connection = cn
.parameter.addwithvalue("@artist", searchTextBox.Text)
End cm
Try
cm.executeNonQuery()
cn.close
cm.dispose()
server.transfer(artistpage.aspx)
This should be enough to get you started or at least thinking of different ways to put it together
you will desire to have as many link search engine optimization as you will discover or place at any which includes sites you could, quite right here on ya, zynga, twitter, everywhere you probable can besides as reference it in different appropriate blogs. the greater website link backs the better the particular rank.