943,649 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 98078
  • MySQL RSS
Jun 19th, 2004
0

MySQL LIKE statement

Expand Post »
I'm trying to creat a search procedure that will search table game and return all rows where columns title, description, platform, and gameid are LIKE parameter searchtext. This parameter is coming from many different pages as a Session("searchtext"), and I'm using a UserControl to send the Session, all pages in the site have the search UserControl.

In the search result page I have the following code (command and connection are in the design page):
Dim dsList As New DataSet
cmdSearch.Connection.Open()
cmdSearch.Parameters("searchtext").Value = Session("searchtext")
If Not Page.IsPostBack() Then
daSearch.Fill(dsList)
lblRecordCount.Text = CStr(dsList.Tables(0).Rows.Count)
dsList = Nothing
dsList = New DataSet
End If
daSearch.Fill(dsList, CInt(lblCurrIndex.Text), CInt(lblPageSize.Text), "game")
dlGames.DataSource = dsList.Tables(0).DefaultView
dlGames.DataKeyField = "gameid"
dlGames.DataBind()
cmdSearch.Connection.Close()

This is my statement (cmdSearch):
SELECT *
FROM game
WHERE (title like '%' +:searchtext+ '%' or description like '%' +:searchtext+ '%' or platform like '%' +:searchtext+ '%' or gameid like '%' +:searchtext+ '%')
ORDER BY title


I'm not sure what I am doing wrong here. This statement is returning all games in the game table. I tried '%gamename%' and it worked fine, I'm assuming I need the single quotes again with the parameter because when I tried without the single qotes it didn't work. This is almost the same command as the one I have for the ShowAllGames command, the only difference is that I added the parameter for the search.

Can anyone help me?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
maxtrixx is offline Offline
11 posts
since Jun 2004
Jun 24th, 2004
0

Re: MySQL LIKE statement

not sure I'm going to be very helpful but...

like '%' +:"searchtext"+ '%'

Try that?
Reputation Points: 115
Solved Threads: 7
Practically a Master Poster
Slade is offline Offline
633 posts
since Mar 2004
Sep 21st, 2007
0

Re: MySQL LIKE statement

This is my script:

mysql_connect ("localhost","root","123");
mysql_select_db(bukutelp);
$sql=mysql_query("select * from daftar where (nama LIKE '%'+nama+'%') LIMIT 0, 10");
$sql_1=mysql_query("select * from daftar where (nama LIKE '%'+nama+'%')");
$rows = mysql_num_rows($sql_1);
IF ($rows%2==0) {$pages = $rows/2;} else {$pages = $rows/2;}
while ($baris=mysql_fetch_array($minta))
{ echo "<br>" ;
echo "<strong>$baris[nama]</strong> ";
echo "<strong>$baris[phone]</strong>"; echo "<br>";
echo "<hr align=left width=200>";
}

end i got error like this

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\buku telp\cari.php on line 12

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\buku telp\cari.php on line 14

what should i do?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
diwan is offline Offline
1 posts
since Sep 2007
Sep 22nd, 2007
0

Re: MySQL LIKE statement

Have you had a look at the syntax for like
http://dev.mysql.com/doc/refman/5.0/...-matching.html
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 12th, 2011
0

mysql like on stored procedure

try this

SELECT *
FROM game
WHERE title like concat('%' ,:searchtext, '%') or description like concat('%' ,:searchtext, '%') or platform like concat('%' ,:searchtext, '%') or gameid like concat('%' ,:searchtext, '%')
ORDER BY title
Reputation Points: 10
Solved Threads: 0
Newbie Poster
concepcionmark is offline Offline
4 posts
since Sep 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Set up a shared mysql database server
Next Thread in MySQL Forum Timeline: 10xvarchar(1) or 10xvarchar(100000), which will have better performance?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC