Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Search MySQL db using two search fields?
Old 08-13-2009, 10:58 PM Search MySQL db using two search fields?
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Hey all,

I've set up a database of employee names and contact info. The db is set up like

Last_Name First_Name City etc.

I have it set up to search for 1st name or last name and return the results. The people using the search would like to have a two fields to search by either first or last name, or both. Do I need to have separate names for the text fields? How would I go about implementing two search fields that work together?
werm82 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-14-2009, 02:41 AM Re: Search MySQL db using two search fields?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
PHP Code:

<?php

include ("include/header.inc.php");
include (
"include/dbconnect.php");

if (
$searchstring)
    {
    
$sql="SELECT * FROM $table WHERE $searchtype LIKE '%$searchstring%' ORDER BY artist ASC";

    
    
$result mysql_query($sql);
    
$resultsnumber mysql_numrows($result);
    
    echo 
"<table cellpadding=2 cellspacing=1 border=0 align=center width=100%><tr><td>Artist Name</td><td>Song Title</td><td>Video</td></tr>";
    echo 
"number of results: $resultsnumber";
    
    
$alternate "2"
        while (
$myrow mysql_fetch_array($result))
        {
        
$artist $myrow["artist"];
        
$id $myrow["id"];        
        
$song $myrow["song"];
        
        if (
$alternate == "1") { 
        
$color "#555555"
        
$alternate "2"
        } 
        else { 
        
$color "#333333"
        
$alternate "1"

            echo 
"<tr bgcolor=$color><td>$artist</td><td>$song</td><td><a href='view.php?id=$id'>Play Video</a></td></tr>"
            }
    echo 
"</TR></TABLE>";
    echo 
"<p>Look <a href='az_index.php'>alphabetically</a> or <a href='$PHP_SELF'>search again</a></p>";

    }


else
    {
?>
    <form method="POST" action="<? $PHP_SELF ?>">

  <table border="0" cellspacing="2">
    <tr>
      <td colspan="2"><b>Advanced Search for ?????</b></td>
      </tr>
    <tr>
      <td valign="top"> 
        <input type="text" name="searchstring" size="35">
      </td><td><input type="submit" value="Submit"></td></tr><tr>
      <td colspan="2"><br><b>Search By:</b><br><br>
        <input type="radio" name="searchtype" value="venue" checked>Venue Name<br>
        <input type="radio" name="searchtype" value="address">Address<br>
        <input type="radio" name="searchtype" value="city">City<br>
        <input type="radio" name="searchtype" value="zip">Zip Code<br>
    <input type="radio" name="searchtype" value="phone">Phone Number
    </tr>    
    </table>
    </form>

<?
    
}

include (
"include/footer.inc.php");
?>
you can edit this to your needs...it should work fine...its an old search script that i used back in the day
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Reply     « Reply to Search MySQL db using two search fields?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43710 seconds with 12 queries