Current location: Hot Scripts Forums » Programming Languages » PHP » database search


database search

Reply
  #1 (permalink)  
Old 08-17-04, 09:27 AM
skyloon skyloon is offline
New Member
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
database search

i just know 1 text box database search, can anyone help for many text boxes database search?
for example, i can key in name in text box, check box and list box, and then press the search button to search from database.
the scripts below are just search from 1 text box only...
can someone teach me for multiple search?
thank you..


PHP Code:

<?php

    $connection 
mysql_connect("localhost","root","");
    
mysql_select_db("help"$connection);
    if(!
$connection)
    {
       echo 
"Couldn't make a connection!!!";
       exit;
    }
    
$db mysql_select_db("help",$connection);
    if(!
$db)
    {
      echo 
"The database disapeared!";
      
mysql_close($connection);
      exit;
    }
    
$max 0;
    
$bmax mysql_query("SELECT * from Staff WHERE StaffID like '%$search%'");
    while (
$number_of_array mysql_fetch_array($bmax))
    {
      
$max++;
    }
?>


PHP Code:

<?php

    
echo "<center><form action=\"search.php\" method=\"get\"><input type=\"text\" name=\"search\"
          value=\"
$search\" style=\"border:1 solid #003366\"> <input type=\"submit\" value=\"Search\" style=\"border:1 solid #000066\">";
    echo 
"</td><td height=\"12\" align=\"right\" bgcolor=\"aliceblue\" width=\"63%\">";
    echo 
"<center>Database Search returned<font color = blue> $max </font>
          items containing \"<i><font color = blue>
$search</font></i>\".</center>";
    echo 
"</td></tr></form></table><br>";
    
$maxresult 10;
    
$sql_text = ("SELECT * from Staff WHERE StaffID like '%$search%'");

    if (!
$page) {
    
$page 1;
    } 
    
$backpage $page 1;
    
$nextpage $page 1;
    
$query mysql_query($sql_text);
    
$start = ($maxresult $page) - $maxresult
    
$num_rows mysql_num_rows($query); 
    if (
$num_rows <= $maxresult) {
    
$num_pages 1
    } else if ((
$num_rows $maxresult) == 0) {
      
$num_pages = ($num_rows $maxresult);
    } else {
    
$num_pages = ($num_rows $maxresult) + 1;
    } 
    
$num_pages = (int) $num_pages;
    if ((
$page $num_pages) || ($page 0)) {
    
error("You have specified an invalid page number");
    }
    
$sql_text $sql_text " LIMIT $start$maxresult";
    
$query mysql_query($sql_text);
    
    if (
$max>$maxresult)
    {
    echo 
"<center>- ";
    if (
$backpage) { 
    echo 
"<a href=\"search.php?search=$search&page=$backpage\">Prev</a>";
    } else {
    echo 
"Prev";
    }
    for (
$i 1$i <= $num_pages$i++) {
    if (
$i != $page) { 
    echo 
" <a href=\"search.php?search=$search&page=$i\">$i</a> ";
    } else { 
    echo 
$i "
    } 
    }
    if (
$page != $num_pages) {
    echo 
"<a href=\"search.php?search=$search&page=$nextpage\">Next</a> -";
    } else {
    echo 
"Next -";
    }
    echo 
"</center>";
    }
?>

PHP Code:

<?php

    $a 
$start 1;
    print
"<TABLE CELLSPACING=\"0\" CELLPADDING=\"0\" BORDER=\"1\" align=center width=\"60%\">";
           print 
"  <TR><TD align=center>Staff ID</TD><TD align=center>Name</TD><TD align=center>IC No</TD></TR>\n";

    while (
$number_of_array mysql_fetch_array($query)) {
    echo 
"<tr>\n"
    echo 
"<TD align=center><font size=\"2\">$number_of_array[StaffID]</TD>\n"
    echo 
"<TD align=center><font size=\"2\">$number_of_array[Name]</TD>\n"
    echo 
"<TD align=center><font size=\"2\">$number_of_array[ICNO]</TD>\n";
    
$a++;
?>
http://img.photobucket.com/albums/v2...oon/search.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-17-04, 11:33 AM
php~pro php~pro is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: In a nice house.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Create variables and use the in your query like

sql = ("SELECT * From your_table WHERE example = '$var1' AND example2 = '$var2' ORDERBY '$var3' ");
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-17-04, 11:46 PM
skyloon skyloon is offline
New Member
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
thanx....
search with multiple text boxes are ok oredi,
but i hv no idea with the check box...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-19-04, 01:48 AM
skyloon skyloon is offline
New Member
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
can do something like this?
if the check box checked, then show the result with the photo, if unchecked, then show the result without photo

thanks....

http://img.photobucket.com/albums/v2...oon/search.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 01:38 PM
How do i search from a form to mysql database using php QTortZ PHP 6 06-02-04 10:57 PM
Simple search script niceguyonline Script Requests 3 03-08-04 12:09 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 12:06 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.