homepage Welcome to WebmasterWorld Guest from 54.227.160.102
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Need Help Building a Search Site Form (PHP,MySQL)
Need a form that searches (queries) a MySQL database
alcheme

10+ Year Member



 
Msg#: 6398 posted 4:48 am on Jan 7, 2005 (gmt 0)

Hello,

I have created a MySQL / PHP publishing database. I want to provide a search.php form that can search the database for certain fields:

- Title
- Date
- Author
- Section

Does anyone know a handy PHP script that will search and print search results based on certain form fields?

Also, how to format them so it shows 20 words from the field 'content'.

-Shane

 

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 6398 posted 4:54 am on Jan 7, 2005 (gmt 0)

what about a few handy dandy threads?

Basics of extracting data from MySQL using PHP [webmasterworld.com]
syntax for selecting first 100 characters from a mysql field [webmasterworld.com]

alcheme

10+ Year Member



 
Msg#: 6398 posted 5:45 am on Jan 7, 2005 (gmt 0)

Thank you Jatar_K...

The second link I found super useful. I am going to read through the first link (forum topic) later tonight and I have found several others from this forum:

[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]

I am working on some test scripts now that I will share for workshopping very soon.

IN the meantime, I hope for continued suggestions or recommendations. Thanks again Jatar_K!

Back in a bit...

~Shane

alcheme

10+ Year Member



 
Msg#: 6398 posted 12:23 am on Jan 8, 2005 (gmt 0)

Here is what I got so far and it works!

search.php

<form method="post" action="search_results.php">
<table width=88% align=center class="border_table">
<tr bgcolor="#55556F">
<td width="22%" bgcolor="#55556F"><p>Search for:</p></td>
<td width="78%"><input type=text name='search' size=60 maxlength=255></td></tr>
<tr bgcolor="#55556F"><td></td>
<td bgcolor="#55556F"><input type=submit></td>
</tr>
</table>
</form>

search_results.php

<?

include("****.php");

if ($search) // perform search only if a string was entered.
{
mysql_connect() or die ("Problem connecting to Database");

$query = mysql_query("SELECT wname, url, title, keywords, description, city, country, category FROM directory WHERE city LIKE '%$search%' wname LIKE '%$search%' title LIKE '%$search%' keywords LIKE '%$search%' description LIKE '%$search%' country LIKE '%$search%' category LIKE '%$search%' url LIKE '%$search%'", $db);

if ($query)
{
echo "<table width=100% border=0 cellpadding=0 cellspacing=5 class=border_playlist_table><tr>";

while ($myrow = mysql_fetch_array($query)) { // Begin while
$wname = $myrow["wname"];
$url = $myrow["url"];
$title = $myrow["title"];
$city = $myrow["city"];
$country = $myrow["country"];
$category = $myrow["category"];
$keywords = $myrow["keywords"];
$description = $myrow["description"];
echo "<tr class=sub_1><td colspan=4>$wname : $category</td></tr>
<tr bgcolor=#55556F><td><p><a href=$url target=_blank>$url</a></p></td>
<td><p>$title</p></td>
<td><p>$city</p></td>
<td><p>$country</p></td></tr>
<tr bgcolor=#55556F><td colspan=4>$keywords</td></tr>
<tr bgcolor=#55556F><td colspan=4>$description</td></tr>
<tr><td colspan=4>&nbsp;</td></tr>";
} // end while
echo "</tr></table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}
?>

Thanks for all your help!

~Shane

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 6398 posted 12:36 am on Jan 8, 2005 (gmt 0)

nice work :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved