•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 422,640 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,669 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 43442 | Replies: 3
![]() |
•
•
Join Date: Jun 2004
Posts: 11
Reputation:
Rep Power: 5
Solved Threads: 0
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?
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?
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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?
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?
Have you had a look at the syntax for like
http://dev.mysql.com/doc/refman/5.0/...-matching.html
http://dev.mysql.com/doc/refman/5.0/...-matching.html
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- jsp and mysql (JSP)
- Communication Link Failure Error (JSP)
- Uploading current php site to another site. (PHP)
- MySQL insert statement (MySQL)
- Table Update Problem (JSP)
- Search facility for a drop down box (MySQL)
- Invision Power Board mysql error when trying to view newly created forums (PHP)
Other Threads in the MySQL Forum
- Previous Thread: Open Source Application Server
- Next Thread: Inserting date in format DD-MM-YYYY in MySQL



Linear Mode