Use PHP + MYSQL as a business card library program

Source: Internet
Author: User


Use PHP + MYSQL to create a name library Program , Supports searching by category and paging.

Step 1: Create a static page as follows.
<Form method = "Post" Action = "find1.php" name = "card" onsubmit = "Return card_validator (this)">
<Table width = "400" border = "0" cellspacing = "0" cellpadding = "0" class = "P10">
<Tr>
<TD colspan = "2" Height = "79">
<Table width = "280" border = "0" cellspacing = "0" cellpadding = "0" class = "P10">
<Tr>
<TD colspan = "3" Height = "37"> enter the Keyword:
<Input type = "text" name = "keyword" class = "C3A">
</TD>
</Tr>
<Tr>
<TD>
<Input type = "radio" name = "inout" value = "N" Checked>
By name </TD>
<TD>
<Input type = "radio" name = "inout" value = "C">
By region </TD>
<TD>
<Input type = "radio" name = "inout" value = "A">
By position </TD>
</Tr>
</Table>
</TD>
</Tr>
<Tr>
<TD colspan = "2" Height = "47">
<Input type = "Submit" name = "query1" value = "">
<Input type = "reset" name = "submit2" value = "clear">
</TD>
</Tr>
</Table>
</Form>
Step 2: Create a database as follows.
Id int (4) No auto_increment
HTTP varchar (25) No
Name varchar (50) No
Email varchar (50) No
GS varchar (200) No
Address varchar (200) No
Yb varchar (20) No
ZW varchar (100) No
Tel varchar (20) No
Fax varchar (20) No
BP varchar (20) No

Step 3: Find the execution Program
<? PHP

If (! Isset ($ show) $ show = 0;

{

If ($ query1 = "Search ")

{

$ Db = mysql_connect ("localhost", "username", "password ");
$ Dbname = mysql_select_db ("database file name", $ dB );
Mysql_query ('select * from Table filename ', $ dB );
$ Limit = 2; // several items are displayed on one page.

// Global $ query, $ queryyy, $ quer;
Switch ($ inout)

{

Case "N ":
// Search by name
$ Query = "select * from card where name like '% $ keyword % '";

$ Queryyy = "select * from card where name like '% $ keyword % 'order by id desc limit $ show, $ limit ";

Break;

Case "C ":
// Search by region
$ Query = "select * from card where address like '% $ keyword %' order by id desc ";

$ Queryyy = "select * from card where address like '% $ keyword %' order by id desc limit $ show, $ limit ";
Break;

Case "":
// Search by position
$ Query = "select * from card where ZW like '% $ keyword %' order by id desc ";

$ Queryyy = "select * from card where ZW like '% $ keyword %' order by id desc limit $ show, $ limit ";
Break;

}
$ Result1 = mysql_query ($ query );
$ Total = mysql_num_rows ($ result1); // The total number of qualified records

$ Quer = mysql_query ($ queryyy, $ dB );
$ Pages = Ceil ($ total/$ limit );
}
}

?>

<P> <font color = "# ff0000" face = "" size = "3"> <strong> <span style = "font-size: 12pt "> <font size =" 4 "color =" #000000 "> the keywords you search for are: </font> </span> </strong> </font>: <font color = Red> <? Echo $ keyword;?> </Font> </P>

<?

Echo "<Table width = '000000' border = '0' cellspacing = '0' cellpadding = '0' align = 'center'>
<Tr>
<TD width = '000000'>
<Div align = 'center'> search for business cards as follows: [<font color = Red> ";
Echo $ total;
Echo "</font>] A business card </div>
</TD>
<TD width = '86'>
<Div align = 'right'> [<font color = Red> ";
Echo $ pages;

Echo "</font>] page </div>
</TD>
</Tr>
</Table> ";

While ($ ROW = mysql_fetch_array ($ quer ))
{

Echo "<Table width = '000000' border = '1' cellspacing = '0' cellpadding = '0' Height = '000000' align = 'center' bordercolordark = '# eeeeee' bordercolorlight = '#666666'>








$ row [GS]


$ row [name] $ row [ZW]

</TD>
</Tr>
<Tr>
<TD colspan = '2'>
<Ul>
<Li> <SPAN class = 'pp10'> Tel: $ row [tel] </span> </LI>
<Li> <SPAN class = 'pp10'> Fax: $ row [Fax] </span> </LI>
<Li> <SPAN class = 'pp10'> URL: $ row [http] </span> </LI>
<Li> <SPAN class = 'pp10'> email address: $ row [eamil] </span> </LI>
<Li> <SPAN class = 'pp10'> address: $ row [address] </span> </LI>
<Li> <SPAN class = 'pp10'> zip code: $ row [Yb] </span> </LI>
<Li> <SPAN class = 'pp10'> BP: $ row [BP] </span> </LI>
</Ul>
</TD>
</Tr>
</Table>
</TD>
</Tr>
</Table> <br> ";

}

$ Vor = $ show + $ limit;
$ Back = $ show-$ limit;
Print "<center> ";

Print "


"; Print "
";
for ($ I = 1; $ I <= $ pages; $ I ++)
{< br> $ new_offset = $ limit * ($ i-1 );
$ parameter = "query1 = $ query1 & keyword = $ keyword & inout = $ inout";

Print "<a href =" $ php_self? Show = $ I & $ parameter "> <B> $ I </B> </a> $ nbsp ";
}
Print "</TD> <TD width =" 45 "> ";
// Display the previous page
If ($ show-$ limit> = 0)
{
Print "<a href =" $ php_self? Show = $ back & $ parameter "> previous page </a> ";
}
Print "</TD> <TD width =" 45 "> ";
// Display the next page
If ($ show + $ limit) <$ total)
{
Print "<a href =" $ php_self? Show = $ vor & $ parameter "> next page </a> ";
}
Print "</TD> <TD width =" 60 "> ";
// Display all messages
// Print "<a href =" $ php_self? Show = all. & $ parameter "> all business cards </a> ";
Print "</TD> </tr> </table> ";
Print "</center> ";
?>
If there is a problem please mailto: lyjrich@sina.com, this program has a problem if you want to display all business cards, I this program has not implemented this function, if you know how to display all the business cards in this program, you may want to mail it to me.

[This article is copyrighted by the author and osuo. If you need to reprint it, please indicate the author and its source]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: