Computing.Net > Forums > Web Development > Beginner's TextBox and Gridview que

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Beginner's TextBox and Gridview que

Reply to Message Icon

Name: Robert J
Date: November 21, 2008 at 23:50:38 Pacific
OS: ASP.NET
CPU/Ram: Pentium 2GB
Product: Visual Studio 2008
Comment:

I have a textbox where I can type multiple text strings and a gridview that displays the result from an SQL SELECT based on what's in the textbox.

For example, if the textbox has "abc def -xyz" then the gridview would display all records that have the substrings 'abc' and 'def' and NOT the substring 'xyz'.

I also want the gridview to refresh whenever the space character is entered. That means right after 'abc' and then 'def'.

How do I do that? Many thanks for your help.




Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: November 22, 2008 at 16:12:42 Pacific
Reply:

You really haven't providied enough information, such as what language you are using. But, I'll give it a shot using PHP. This example will require the user to submit the page to see the results. You will need to incorporate some AJAX to have the grid update dynamically. There's just way to much in your request to do all at once:

<?php

if (isset($_POST['search_string']))
{
//Convert search string into an array
$search_ary = explode(' ', trim($_POST['search_string']));
//Process each search string part
foreach ($search_ary as $str)
{
if($str!='')
{
if(substr($str, 0, 1)=='-')
{
$where_parts[] = "db_field NOT LIKE '%".substr($str, 1)."%'";
}
else
{
$where_parts[] = "db_field LIKE '%".$str."%'";
}
}
}

$query = "SELECT * FROM table WHERE " . implode(' AND ', $where_parts);
$result = mysql_query($query) or die(mysql_error());
$output = "<table>\n";
echo "<tr><th>Col 1</th><th>Col 2</th><th>Col 3</th></tr>\n";
while ($record = mysql_fetch_assoc($result))
{
$output .= "<tr>";
$output .= "<td>{$record['field1']}</td>";
$output .= "<td>{$record['field2']}</td>";
$output .= "<td>{$record['field3']}</td>";
$output .= "</tr>";
}
$output .= "<table>\n";
}
?>

<html>
<body>

<form name="test" method="POST">
Enter Search Criteria: <input type="text" name="search_string" />
<button type="submit">Submit</button>
</form>
<br /><br />
<?php echo $output; ?>

</body>
</html>

Michael J


-1
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Beginner's TextBox and Gridview que

a box and a save button www.computing.net/answers/webdevel/a-box-and-a-save-button/1860.html

What tool/language should i use? www.computing.net/answers/webdevel/what-toollanguage-should-i-use/2301.html

User login and password for website www.computing.net/answers/webdevel/user-login-and-password-for-website/9.html